  | |  Unable to see source document after using for-each on a converted
node-set | Unable to see source document after using for-each on a converted
node-set 2003-02-07 - By Edwards, Peter
I have a simple document: <?xml version="1.0" encoding="UTF-8"?> <root> <name>Test</name> <description>D1</description> <number>42</number> <description>D2</description> </root>
And a stylesheet that groups certain elements together: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" extension-element-prefixes="exslt" exclude-result-prefixes="exslt" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:variable name="tree"> <test>name</test> <test>description</test> </xsl:variable> <xsl:template match="root"> <out> <!-- process the specific nodes defined in the variable --> <xsl:for-each select="exslt:node-set($tree)/test"> <xsl:variable name="tag" select="."/> <results group="{$tag}"> <xsl:for-each select="/root/*[name() = $tag]"> <xsl:copy-of select="."/> </xsl:for-each> </results> </xsl:for-each> </out> </xsl:template> </xsl:stylesheet>
The expected output is: <?xml version="1.0"?> <out> <results group="name"> <name>Test</name> </results> <results group="description"> <description>D1</description> <description>D2</description> </results> </out>
In the case of Xalan (v2.4.1 with JDK1.4.1) the output is: <?xml version="1.0" encoding="UTF-8"?> <out> <results group="name"/> <results group="description"/> </out>
I ran the same stylesheet with XSLTProc and got the output I expected. It is as though the Xalan processor cannot see the root element when it is operating within a for-each clause walking a converted nodeset. Does anyone know if this is a know fault or is it behaving according to spec and my expectations were wrong. Obviously there are better ways of grouping things and I have changed the whole stylesheet but suspect I have found a problem.
Pete Edwards
|
|
 |