Re: [xslt] Selecting on nodeset in variable from stylesheet



At 10:23 -0500 12/12/03, Daniel Veillard wrote:
>On Fri, Dec 12, 2003 at 04:20:25PM +0100, Elizabeth Mattijsen wrote:
>  > I would expect to see "bar" as the result.
>  > Am I doing here that I shouldn't be doing?
>   Using a result value tree for something it's not intended to !

Too bad.  It feels like a "natural" thing to do.  And the error 
message isn't very helpful in that respect  ;-(


>The spec is at http://www.w3.org/TR/xslt

Hmmm... I can't find a "result value tree" in here.  I assume you 
mean "result tree fragment" as in paragraph 11.1:

11.1 Result Tree Fragments

Variables introduce an additional data-type into the expression 
language. This additional data type is called result tree fragment . 
A variable may be bound to a result tree fragment instead of one of 
the four basic XPath data-types (string, number, boolean, node-set). 
A result tree fragment represents a fragment of the result tree. A 
result tree fragment is treated equivalently to a node-set that 
contains just a single root node. However, the operations permitted 
on a result tree fragment are a subset of those permitted on a 
node-set.  An operation is permitted on a result tree fragment only 
if that operation would be permitted on a string (the operation on 
the string may involve first converting the string to a number or 
boolean). In particular, it is not permitted to use the /,// , and [] 
operators on result tree fragments.  When a permitted operation is 
performed on a result tree fragment, it is performed exactly as it 
would be on the equivalent node-set.

When a result tree fragment is copied into the result tree (see [11.3 
Using Values of Variables and Parameters with xsl:copy-of ]), then 
all the nodes that are children of the root node in the equivalent 
node-set are added in sequence to the result tree.

Expressions can only return values of type result tree fragment by 
referencing variables of type result tree fragment or calling 
extension functions that return a result tree fragment or getting a 
system property whose value is a result tree fragment.



>you must use a non-standard extension called node-set() to do what
>you want, and it's noti correct from an XSLT-1.0 point of view.

So I guess my stylesheet should have looked like this:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:exslt="http://exslt.org/common";
>
<xsl:template match="/">

<xsl:variable name="foo"><name>bar</name></xsl:variable>
<xsl:value-of select="exslt:node-set($foo)/name"/>

</xsl:template>
</xsl:stylesheet>


Ok, fair enough.  I think it is a particularly ugly thing that you 
need to do to get the result you expect.  I assume that will be 
better in XSLT 2.0...  ;-)


Thanks for the feedback, Daniel.


Liz



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]