Using XSLT to extract content from your Unitrunker files
Unitrunker stores and exports data in XML. The idea here is to use a very powerful tool for data extraction from XML. XSLT output is not limited only to XML or HTML. You can use XSLT to output comma delimited text. Some implications are:
- generate comma delimited or CSV file for importing into a spreadsheet program like Excel
- generate HTML for publishing on the web
This sample stylesheet extracts talkgroups as comma delimited text. To keep things simple, the sample provided will only operate on the first system it finds in the XML source file.
- Step one: use the "Export System" feature to create an XML file containing only the selected system. Save the file to your desktop or other convenient folder.
- Step two: get msxsl.exe from Microsoft here. Save this tiny program to the same folder as your XML file. A similar tool called 'xsltproc' exists for Mac and Linux users.
- Step three: download and save this XSLT file to the same folder where you saved the files in each of steps one and two.
To recap, you should have at least three files in a working directory: msxsl.exe, groups,xslt, and your trunking system file ending in ".xml".
- Step four: open a command window and change the command window's working directory to match the directory above.
- Step five: you want to run ths msxsl utility in such a way as it reads the XML data file and applies the transformation rules in the XSLT file to produce an output file. We'll call the output file extracted.txt but you can name it anything you wish. Type this command:
msxsl system.xml groups.xsl -o extracted.txt
View the output file extracted.txt in notepad or open the file in your favorite spreadsheet program.
msxsl produces UTF-16 Unicode files. Notepad and Excel recognize this text format. msxsl depends upon a recent version of MSXML. If you've a recent version of Internet Explorer, you have it.
Mac and Linux
The command line equivalent for msxsl.exe is xsltproc. The syntax is slightly different in that the placement of stylesheet and XML file are reversed so the above example would read:
xsltproc groups.xsl system.xml -o extracted.txt.
The above sample extracts only talkgroups for the first system. Write your own transformation file to extract sites, channels, or groups from any system in the Unitrunker.xml data file. You'll find a tutorial on the subject here.