Subject: Re: [xsl] ClassCastException|
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Sat, 13 Dec 2003 01:23:05 +0100
Is there somewhere I can find an example of the difference between a node set and a result tree fragment?
A node set is a set of nodes grabbed from the a source tree, either the original input, returned by document(), or constructed with an XPath extension function which returns a node set.
A result tree fragment (RTF) is a tree constructed in a style sheet variable. If you use xsl:variable without the select attribute, you are always creating a RTF. RTFs can only be created in stylesheet variables.
This puts a node set into the variable <xsl:variable name="foo" select="/foo"/>
This variable holds a string: <xsl:variable name="foo" select="'/foo'"/>
This constructs a RTF. It holds a text node as the single child of the root node of the RTF. The root node of a RTF is similar to the root node of a source tree <xsl:variable name="foo">/foo</xsl:variable> While dereferencing this variable gets the same value as for the variable above in all useful situations, they are different.
This constructs a RTF too. It contains eleent nodes as the children of the root node: <xsl:variable name="foo"> <xsl:copy-of select="/foo"/> </xsl:variable>
If you now think the distinction between a node set and a RTF is silly, then you may have a point. The spec authors thought treating RTFs the same as source trees might prove difficult and/or prevent optimizations, and they decided to play safe: A RTF can only be copied into the result tree or used via string conversion in an XPath expression, which means you can't select nodes from them.
The following expression will always be valid, regardless which of the for forms above is used. concat($foo,'/bar') If the source xml was <foo>/foo</foo> the result is always the same, the string "/foo/bar".
Is a node set just a "path", or set of nodes with only one "destination" node vs. a result tree that gives multiple node sets?
I don't understand the question. Some XSLT statements require the XPath expression in the select attribute to evaluate into a node set. I'm not sure what you count as "a path", the expression (/foo|$foo/bar|document('foo.xml')) ought to evaluate in a node set too, provided $foo holds a node set.