Tuesday, December 14, 2010

XSL 1.0 vs 2.0

XML-23006: (Error) value does not match required type
Many of the XSL templates that were working for a long time started failing after upgrading to XSL 2.0.
Almost of all of the failing XPath expressions were identified to be not absolute expressions(starting with //).

The problem was eventually identified to be what certain XPath expressions returned - node or node set -
difference between XSL 1.0 and 2.0 behavior. Wherever an XPath expression, such as "string(//ns1:elemX)", returned a node set in XSL 2.0 led to a run time error. The same expression returned the first matching node when XSL 1.0 was used and did not trigger an error.

This is how the above expression was rewritten to fix it with XSL 2.0
          string((//ns1:elemX)[1]) - Note that this expression is entirely different from string(//ns1:elemX[1]) which would return a node set as opposed to the first node.