Re: [xsl] xsl:sequence

Subject: Re: [xsl] xsl:sequence
From: "tom tom" <tomxsllist@xxxxxxxxxxx>
Date: Mon, 07 Aug 2006 15:57:36 +0100
<xsl:sequence select="." /> is constructing new nodes in the output that is, in effect, a copy-of the context node.

No, it selects the current node. (unlike <xsl:copy-of which would
construct a copy). If the xsl:sequence is being used to generate
an output result tree, then the difference is slight, as there is an
implied copying anyway in that construction, but if the current template
is being used to construct the value of a variable.there is a big
difference. In one case the variable will have a reference to teh
current node, and in teh other it will have a reference to a copy.

I was referring to constructing a copy of the node in the output and by the sounds of it I'm right in still calling this a copy. I naively hadn't thought about its use when constructing a value of a variable. If a variable value is a reference rather than a copy what advantages does that provide?



> Does <xsl:sequence select="@price"/> not assign an attribute node to the
> variable $prices? If so surely this is wasteful?

it references an _existing_ attribute node, but this is coerced to an
atomic xsl:double value because of the as attribute which specifies the
variable holds a sequence of doubles. I'm not clear where you see the
waste.

I was thinking that an attribute node contains a text node. Reading up on it an attribute node seems to *be* both the attribute name and its value. When it is co-erced to an atomic xs:double value it somehow loses the attribute name part and just takes on the value - this is what I was referring to as waste.



From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] xsl:sequence
Date: Mon, 7 Aug 2006 11:20:55 +0100

> Apologies for these seemingly random questions but I have read numerous
> resources and am still struggling to understand why xsl:sequence is so
> important.

It's important, especially in variable and function definitions, as it
allows the return of _existing_ nodes rather than copies of nodes.


> <xsl:sequence select="." /> is constructing new nodes in the output that is,
> in effect, a copy-of the context node.


No, it selects the current node. (unlike <xsl:copy-of which would
construct a copy). If the xsl:sequence is being used to generate
an output result tree, then the difference is slight, as there is an
implied copying anyway in that construction, but if the current template
is being used to construct the value of a variable.there is a big
difference. In one case the variable will have a reference to teh
current node, and in teh other it will have a reference to a copy.

> 2. I also understand sequence allows you to construct a sequence of
> different datatypes in one expression,
>
> What, then, is the point of the concat function in XSLT 2? ie could

concat serves a completely different purpose, it concatenates strings,
producing a single string.

> What, then, is the point of the concat function in XSLT 2? ie could

> <xsl:sequence select="concat(meta/brand/text(), ' | ', genre/text())"/>

> be rewritten:

> <xsl:sequence select="meta/brand/text(), ' | ', genre/text()"/>

The first one makes a sequence of one item, a string.

The second one makes a sequence of three items, a text node, a string and
a text node

Compare

<xsl:value-of separator=",">
  <xsl:sequence select="concat(meta/brand/text(), ' | ',
  genre/text())"/>
</xsl:value-of

<xsl:value-of separator=",">
  <xsl:sequence select="meta/brand/text(), ' | ',
  genre/text()"/>
</xsl:value-of



> Does <xsl:sequence select="@price"/> not assign an attribute node to the
> variable $prices? If so surely this is wasteful?

it references an _existing_ attribute node, but this is coerced to an
atomic xsl:double value because of the as attribute which specifies the
variable holds a sequence of doubles. I'm not clear where you see the
waste.

David


_________________________________________________________________
Dont just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/


Current Thread