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
- demo.xml -- The simple example XML document listed in the
article and used to demonstrate XPath expressions. A plain text version is available at
demo.txt.
Also, this link also provides
a convenient tree view of all the XPath nodes in the document -- you can view (and print) this
to help you interpret your XPath expressions!
You will need a browser that supports CSS1
(IE 5+, Netscape 6+/Mozilla, Opera 6+, KConqueror, etc.) to properly view this document.
- longer-demo.xml -- A longer demo XML document, that you
play with using the example XSLT style sheets.
article and used to demonstrate XPath expressions. A plain text version is available at
longer-demo.txt.
Also, this link also provides
a convenient tree view of all the XPath nodes in the document -- you can view (and print) this
to help you interpret your XPath expressions!
You will need a browser that supports CSS1
(IE 5+, Netscape 6+/Mozilla, Opera 6+, KConqueror, etc.) to properly view this document.
- test-absolute-paths.xsl -- A simple XSLT stylesheet that
takes an absolute path and prints out each matched node, surrounded by the strings
START NODE-- and --END NODE. Documentation inside the style sheet shows you where to edit
this file to create your own XPath expressions. Note that, in the case of matched attribute
nodes, ths prints out START NODE -- --END NODE, with nothing in between!
- test-relative-paths.xsl -- A more comple XSLT stylesheet
that lets you test relative XPath expressions. IN this case you need to enter two XPath expressions:
one that uses absolute XPath expressions to define the starting point for the relative paths,
and the relative paths. How this works -- and where to edit the file to change the paths --
is explained inside the stylesheet document.
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:
- 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.
- 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.
- 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