>XSL Tools and XPath 2.0 Validation

>Bug 226245 has been opened since the early stages of XSL Tools 0.5. This bug requests validation support of XPath 2.0 expressions within XSLT 2.0 stylesheets. Unfortunately we have not been able to provide direct support for this within XSL Tools because of some ip issues with various XPath 2.0 parsers and processors. That is until the recent contribution of the PsychoPath XPath 2.0 project. PsychoPath was one fo the hidden gems hanging out on Sourceforge, that did not seem to get much attention. It started out as a college project and pretty much lay dormant once the project was over. However it is being given a new lease on life as an eclipse contribution to XSL Tools.

For those that do not know, XPath 2.0 is a much more powerful and expressive language than XPath 1.0. XPath 2.0 has been in development for several years, and was finally a W3C Recommendation in 2007. Evan Lenz outlines some of the differences between XPath 1.0 and XPath 2.0.

PsychoPath itself is based on a 2005 draft of the XPath 2.0 specification. It provides not only the parsing functionality but a full blown XPath 2.0 Schema Aware processor. It is still the only known Java open source implementation that is Schema Aware. Saxon-SA has a pay version, and Saxon-B is not schema aware. I will go into more on the processing aspects of PsychoPath in a later post, but this post is focused on the XPath parsing ability.

XSL Tools does real-time as you type validation of the XPath expressions for XSLT 1.0, it currently errors out on unknown expressions and functions that it encounters in XSLT 2.0 styelsheets. This is due to the fact that underneath it is trying to use the Xalan XPath 1.0 engine to parse a XPath 2.0 expression. This of course gives a XPath Parser Exception and gives a false negative on the XPath 2.0 expressions in XSLT 2.0. PsychoPath will help eliminate this false negative and parsing an XPath 2.0 expression is pretty straight forward. The following unit test demonstrates how to setup up the parser.


public void testParseValidXPathExpression() throws Exception {
XPathParser parser = new JFlexCupParser();
String xpath = "some $x in /students/student/name satisfies $x = \"Fred\"";
XPath path = parser.parse(xpath);
}

The above test will pass if no exception is thrown. If the parsing fails, an XPathParserException is thrown. Testing for an invalid expression is just as straight forward.


public void testParseInvalidXPathExpression() throws Exception {
try {
XPathParser xpp = new JFlexCupParser();
String xpath = "for in /order/item return $x/price * $x/quantity";
XPath path = xpp.parse(xpath);
fail("XPath parsing suceeded when it should have failed.");
} catch (XPathParserException ex) {

}
}

PsychoPath is currently moving it’s way through the eclipse IP process and will hopefully clear it in time for Galileo. The current plan is to implement support for bug 226245 early in 1.0M6. The validator will be smart enough to know that it is using an XSLT 2.0 Stylesheet and use the appropriate parser to validate the expression. There are also possibilities probably after XSL Tools 1.0 is officially released in June, to enhance the XPath View so that either an XPath 1.0 processor or XPath 2.0 processor can be used.

The long term plan is to run PsychoPath against the W3C test suite that covers the XPath 2.0 functionality of XQuery 1.0, and make it as conformant as possible to the specification. In fact, if any students are interested, we do have a Google Summer of Code idea out for implementing the test suite and fixing compliance issues with the parser.

Advertisements
This entry was posted in eclipse, xml, xpath, xslt. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s