Checking XPath Expressions

The Xalan package has a handy example program, ApplyXPath.java, that enables you to apply an XPath expression to a document and see what the results would be, which is great for testing. To run this example, you need to compile ApplyXPath.java into ApplyXPath.class using the java.exe tool that comes with Java.

As an example, I’ll apply the XPath expression “PLANET/NAME” to planets.xml using ApplyXPath.class. Here’s the result, displaying all <NAME> elements that are children of <PLANET> elements (the <output>tags are added by ApplyXPath):

%java ApplyXPath planets.xml PLANET/NAME 
<output> 
<NAME>Mercury</NAME><NAME>Venus</NAME><NAME>Earth</NAME> 
</output> 

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.