[Home] [By Thread] [By Date] [Recent Entries]
On 8/9/06, tom tom <tomxsllist@xxxxxxxxxxx> 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?
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
|

Cart



