Kenneth M. Cruikshank
Simple Powershell script for XSLT

Kenneth M. Cruikshank
Kinect Projects

Another in a series of example Powershell scripts that may be of use.


XSLT is a functional language desiged for the transformation of data. It is a useful tool. For example, the thesis database I did for the department puts and XML file on the web. When the user ewquests to see the data, the XSLT takes the input request and proceses it for the desirec output (e.g., sort by date, or only show theses with a specific keyword). This is all done by passing parameters to the XSLT stylesheet at JavaScript reads from the drop-boxes on the web page. The transformation is then done using JavaScript on the local computer. Saving many round trips between client and server.

As an example, I will use a USGS format for streamflow data, and convert it to a human readable text file (which is here a comma separated file, which could be read into a spreasheet, likw MS Excel). I have an example WaterML file here, but you can visit the USGS site and download your own.

  • If you need background on XML:
  • To get started with XSLT:
  • WaterML format:
  • WaterML data sets:

The particular XSLT I have here for download is set up with "Placeholders" for completing the output by showind the query that created the data file. It was set up as a learning exercise for students. You can get an idea of how to complete the XSLT by using the "Write-Console.ps1" script, which does a similar transformation byt sents the output to the screen.

In powershell, all we have to do is "introduce" and XML file and and XSLT file to each other. It is a simple 3-line script. The last line will create a text file

$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.load( "WaterML2txt.xslt" )
$xslt.Transform( "WaterML.xml", "WaterML.txt" )


Geology Department

Copyright © 1994-2015 · K.M. Cruikshank ·