Ian's books | CPU Magazine

Core XML: The XPath Language (Part 2)

As described in the December 2002 issue of CPU - Computer Power User magazine.

Examples

Playing with the Style sheet: XRay XML Editor

For XSLT, one of my favourites Windows tools is a simple, free XML / XSLT editor named XRay, available from Architag at http://www.architag.com/xray. This downloads and installs like a regular Windows application, so you should have no problems with it.

Xray lets you select an XML document and an XSLT stylesheet, and then displays a third window showing the results of the XSLT transformation. The best part is that the result is shown in real time -- the output changes instantaneneously as you edit the XML or XSLT! It's a great way to try out different XPath expressions, and quickly see the results.
NOTE: download the XML parser --
You may also need to install the Microsoft XML parser components. These are freely available from Microsoft: just go to http://www.microsoft.com and search for "MSXML". You will need to select the link labelled "Download MSXML Parser 3.0 Service Pack 2", and follow the instructions provided. At the same time, you may also want (from this same page) to follow the link labeled " Download Microsoft XML Core Services (MSXML) 4.0 Service Pack 1", which is a newer version of the XML toolkit. It's probably best to download and install both Versions 3 and 4, as some XML applications require nonstandard features only available in Version 3.

How XRay works --
Once Xray is running, you can open XML or XSLT files simply by dragging them into the application window (or you can also use the File --> Open ... menu to do so). To run a style sheet on an XML document, simply follow these three simple steps:

  1. Select File --> New XSL Transform from the file menu. This produces a window labeled "Transform." This window has two pull-down menus on it -- one labeled XML document, the other labeled XML style sheet. There is also a checkbox labeled Auto Update. Make sure this is checked so that you can see the transformation results in real time.
  2. In the "Transform" window, use the XML document drop-down menu to select the XML file (e.g. demo.xml) you want to transform. Note that this file must already be opened in the XRay editor window.
  3. In the "Transform" window, use the XML styel sheet drop-down menu to select the XSLT style sheet you want to use (e.g. test-absolute-paths.xsl). Note that this file must already be opened in the XRay editor window. Once this is done, the transformed results will automatically appear in the transform window.
And that's it! Now simply edit the XPath expressions in the style sheet (the comment text in the style sheet explains where), and watch the results in the tranform window!

Tutorials, Books, and References