DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21713>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21713 XPath query with variable returns extra null node sequence Summary: XPath query with variable returns extra null node sequence Product: XalanJ2 Version: 2.5 Platform: PC OS/Version: All Status: NEW Severity: Major Priority: Other Component: org.apache.xpath AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] When using an xsl:variable in a select statement for an attribute, the string conversion doesn't work correctly. The variable is turned into a number of nodes, (in my case, two), one being valid, and the other being null..... In other words, the following crashes when applied to the test.xsd file: <xsl:variable name="doctype" select="//RootElementName"/> <xsl:template match="/"> <xsl:apply-templates select="//FirstElem"/> </xsl:template> <xsl:template match="FirstElem"> <document> <first-template> Found element with name <xsl:value-of select="$doctype" /> </first-template> <xsl:apply-templates select="./xs:[EMAIL PROTECTED]"></xsl:apply- templates> </document> </xsl:template> Where as explicitly casting the $doctype variable to string works correctly, as in this example: <xsl:variable name="doctype" select="//RootElementName"/> <xsl:template match="/"> <xsl:apply-templates select="//FirstElem"/> </xsl:template> <xsl:template match="FirstElem"> <document> <first-template> Found element with name <xsl:value-of select="$doctype" /> </first-template> <xsl:apply-templates select="./xs:[EMAIL PROTECTED] ($doctype)]"></xsl:apply-templates> </document> </xsl:template> Below are the templates, separated by a line of hashes (###) ##################################################################### # Test file to apply the templates to: ##################################################################### <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <RootElementName>FirstElem</RootElementName> <FirstElem> <xs:element name="FirstElem"> <xs:complexType> <xs:sequence> <xs:element name="FirstChild"/> <xs:element name="SecondChild"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="SecondElem"> <xs:complexType> <xs:sequence> <xs:element name="ThirdChild"/> <xs:element name="FourthChild"/> </xs:sequence> </xs:complexType> </xs:element> </FirstElem> </xs:schema> ##################################################################### # First xslt template. This one crashes: ##################################################################### <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tsd="http://namespaces.softwareag.com/tamino/TaminoSchemaDefinition"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:variable name="doctype" select="//RootElementName"/> <xsl:template match="/"> <xsl:apply-templates select="//FirstElem"/> </xsl:template> <xsl:template match="FirstElem"> <document> <first-template> Found element with name <xsl:value-of select="$doctype" /> </first-template> <xsl:apply-templates select="./xs:element [EMAIL PROTECTED]"></xsl:apply-templates> </document> </xsl:template> <xsl:template match="xs:element"> <second-template> found template with name <xsl:value-of select="$doctype" /> </second-template> <xsl:call-template name="textIndex"/> </xsl:template> <xsl:template name="textIndex"> <xs:annotation> <xs:appinfo> <tsd:elementInfo> <tsd:physical> <tsd:native> <tsd:index> <tsd:text/> </tsd:index> </tsd:native> </tsd:physical> </tsd:elementInfo> </xs:appinfo> </xs:annotation> </xsl:template> </xsl:stylesheet> ##################################################################### # Second xslt template. This one works: ##################################################################### <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tsd="http://namespaces.softwareag.com/tamino/TaminoSchemaDefinition"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:variable name="doctype" select="//RootElementName"/> <xsl:template match="/"> <xsl:apply-templates select="//FirstElem"/> </xsl:template> <xsl:template match="FirstElem"> <document> <first-template> Found element with name <xsl:value-of select="$doctype" /> </first-template> <xsl:apply-templates select="./xs:[EMAIL PROTECTED] ($doctype)]"></xsl:apply-templates> </document> </xsl:template> <xsl:template match="xs:element"> <second-template> found template with name <xsl:value-of select="$doctype" /> </second-template> <xsl:call-template name="textIndex"/> </xsl:template> <xsl:template name="textIndex"> <xs:annotation> <xs:appinfo> <tsd:elementInfo> <tsd:physical> <tsd:native> <tsd:index> <tsd:text/> </tsd:index> </tsd:native> </tsd:physical> </tsd:elementInfo> </xs:appinfo> </xs:annotation> </xsl:template> </xsl:stylesheet> ##################################################################### # Stack trace ##################################################################### [EMAIL PROTECTED] lib]# java - cp .:./xalan.jar:./xercesImpl.jar:./xmlParserAPIs.jar: org.apache.xalan.xslt.Process -IN test.xsd -XSL test.xslt -EDUMP <?xml version="1.0" encoding="UTF-8"?> <document xmlns:tsd="http://namespaces.softwareag.com/tamino/TaminoSchemaDefinition" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <first-template> Found element with name FirstElem</first-template> <second-template> found template with name FirstElem</second-template> <xs:annotation> <xs:appinfo> <tsd:elementInfo> <tsd:physical> <tsd:native> <tsd:index> <tsd:text/> </tsd:index> </tsd:native> </tsd:physical> </tsd:elementInfo> </xs:appinfo> </xs:annotation> </document> ; SystemID: file:///usr/local/jakarta-tomcat-4.1.24/webapps/SG/WEB- INF/lib/test.xslt; Line#: 14; Column#: 62 javax.xml.transform.TransformerException: java.lang.NullPointerException at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates (TransformerImpl.java:2323) at org.apache.xalan.templates.ElemLiteralResult.execute (ElemLiteralResult.java:696) at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes (ElemApplyTemplates.java:425) at org.apache.xalan.templates.ElemApplyTemplates.execute (ElemApplyTemplates.java:215) at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates (TransformerImpl.java:2318) at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode (TransformerImpl.java:2185) at org.apache.xalan.transformer.TransformerImpl.transformNode (TransformerImpl.java:1263) at org.apache.xalan.transformer.TransformerImpl.transform (TransformerImpl.java:671) at org.apache.xalan.transformer.TransformerImpl.transform (TransformerImpl.java:1179) at org.apache.xalan.transformer.TransformerImpl.transform (TransformerImpl.java:1157) at org.apache.xalan.xslt.Process.main(Process.java:1025) --------- java.lang.NullPointerException at org.apache.xpath.axes.DescendantIterator.nextNode (DescendantIterator.java:247) at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:318) at org.apache.xpath.objects.XNodeSet.compare(XNodeSet.java:537) at org.apache.xpath.objects.XNodeSet.equals(XNodeSet.java:735) at org.apache.xpath.operations.Equals.operate(Equals.java:83) at org.apache.xpath.operations.Operation.execute(Operation.java:147) at org.apache.xpath.axes.PredicatedNodeTest.executePredicates (PredicatedNodeTest.java:377) at org.apache.xpath.axes.PredicatedNodeTest.acceptNode (PredicatedNodeTest.java:514) at org.apache.xpath.axes.AxesWalker.nextNode(AxesWalker.java:407) at org.apache.xpath.axes.WalkingIterator.nextNode (WalkingIterator.java:229) at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:318) at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes (ElemApplyTemplates.java:310) at org.apache.xalan.templates.ElemApplyTemplates.execute (ElemApplyTemplates.java:215) at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates (TransformerImpl.java:2318) at org.apache.xalan.templates.ElemLiteralResult.execute (ElemLiteralResult.java:696) at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes (ElemApplyTemplates.java:425) at org.apache.xalan.templates.ElemApplyTemplates.execute (ElemApplyTemplates.java:215) at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates (TransformerImpl.java:2318) at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode (TransformerImpl.java:2185) at org.apache.xalan.transformer.TransformerImpl.transformNode (TransformerImpl.java:1263) at org.apache.xalan.transformer.TransformerImpl.transform (TransformerImpl.java:671) at org.apache.xalan.transformer.TransformerImpl.transform (TransformerImpl.java:1179) at org.apache.xalan.transformer.TransformerImpl.transform (TransformerImpl.java:1157) at org.apache.xalan.xslt.Process.main(Process.java:1025) [EMAIL PROTECTED] lib]# ##################################################################### ##################################################################### Tested on the following platforms: Win2k, Linux (RH 7.2) With the following Sun JDKs: 1.3.1, 1.4.1_02 (Win2k) JDK 1.3.1_07-b02 (Linux) The really weird thing is that these files work perfectly on JDK 1.4.1_03. I find that spooky. So this could be a Sun java bug. I may also report this bug there.
