[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xsl:sequence

Subject: Re: xsl:sequence
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 9 Aug 2006 12:16:31 +0100
selecting element from sequence xsl
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?

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.