The Apache Xalan-J XSLT compiler (XSLTC) used in JAXP and Java runtimes ignores
XPath predicates in xsl:key elements since the class
'org.apache.xalan.xsltc.compiler.Stylesheet' was rearranged in august 2003 to
reorder the compilation of top level XSLT elements (including keys) to respect
dependencies between global XSLT variables and keys. Method 'compileTopLevel'
was changed to emit code also for key elements and not emit code calling the
method generated by 'compileBuildKeys'. For this reason the byte code for each
key element is generated twice: First time into generated method 'buildKeys'
from 'compileBuildKeys' and second time into generated method 'topLevel' from
'compileTopLevel'. Method 'buildKeys' is still necessary, because it is called
by the XSLT 'document' function, if additional input documents are loaded later.
Unfortunately the translate method of some XPath elements expected to be called
only once and they remove sub elements while their first execution. So all XPath
predicates get lost in class 'org.apache.xalan.xsltc.compiler.FilterExpr' and
'org.apache.xalan.xsltc.compiler.Step' by a remove operation on the
'_predicates' container while the execution from 'compileBuildKeys'. So
'compileTopLevel' generates wrong code for all key elements containing
predicates in their XPath expressions.
The attached patch changes the 'FilterExpr', 'ParentLocationPath' and 'Step'
class to use an index variable to determine the current predicate and to not
remove them. This patch was tested with the current CVS version of JAXP, the
current Subversion version of Xalan (last change of Xalan tree in revision
889881) and with Sun JDK 1.5.0_14, 1.5.0_15, 1.6.0_04, 1.6.0_05 and 1.6.0_18.
This bug exists also in Sun JRE 1.6 (1.6.0 up to 1.6.0_18) and JRE 1.5 (since
1.5.0_12 up to 1.5.0_22). The last Sun JRE version with correct handling of
xls:key elements is 1.5.0_11.
I submitted my patch in March 2008 to the Apache Xalan-J project and file a bug
report directly to Sun Microsystems with a hyperlink to my patch in the Apache
bug tracker. Here are these entries:
My contribution to the Apache Xalan-J project inside the Jira bug tracker
contains a test program as JAR file to diagnose the problem and fixes in form of
JAR files to be installed into '../jre/lib/endorsed' directories of Sun JRE
The first version of my patch submitted in March 2008 caused an infinite
recursion with certain XPath expressions. The JAXP regression tests
'bug6175602/Test.java' and 'bug6537167/Test.java' failed for this reason (see
The new version from January 2010 solve this problem. Please take a look on the
test protocols in the Apache bug tracker entry.
I started a discussion topic about this patch and the consequences to the
OpenSHORE open source project here:
Helge Schulz â€“ http://OpenSHORE.org