xsl-list
[Top] [All Lists]

Re: [xsl] xsl:sequence

2006-08-09 04:17:02
On 8/9/06, tom tom <tomxsllist(_at_)hotmail(_dot_)com> wrote:
Can anyone tell me when I should be using value-of, when i should be using
copy-of and when I should be using sequence?

The difference between value-of and copy-of is pretty straightforward,
the string value of the element vs a deep-copy of the element.  The
difference between copy-of and xsl:sequence is more subtle and can be
highlighted with this example:

XML Source:
<foo>a<bar>b</bar>c</foo>

XSLT:
<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:variable name="sequ" as="element()">
        <xsl:sequence select="/foo/bar"/>
</xsl:variable>

<xsl:variable name="copy" as="element()">
        <xsl:copy-of select="/foo/bar"/>
</xsl:variable>

<xsl:template match="/">
        <result>
                <sequence><xsl:copy-of select="$sequ/parent::*"/></sequence>
                <copy><xsl:copy-of select="$copy/parent::*"/></copy>
        </result> 
</xsl:template>

</xsl:stylesheet>

Output:

<result>
        <sequence>
                <foo>a
                        <bar>b</bar>c
                </foo>
        </sequence>
        <copy/>
</result>

Here you can see that the sequence has copied the parent node through,
while the copy hasn't.

This is because the variable holding the sequence contains a pointer
to the element in the orinal source, and therefore knows its parent.
The variable holding the copy of the element hold just a copy, there
is no parent so nothing is copied to the output.

I hope this helps explain it a little better - sequence refers to
elements in there orginal source location, copy-of creates a
deep-equal copy.

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>