Re: [xsl] xsl:value-of, xsl:copy, xsl:copy-of

Subject: Re: [xsl] xsl:value-of, xsl:copy, xsl:copy-of
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 6 Dec 2004 16:15:51 GMT

   Can anyone provide a quick line or two that defines and
   differentiates xsl:value-of, xsl:copy and xsl:copy-of?  I understand
   some of the differences and can get more info from books and online,
   but in putting some training materials together I want to make sure I
   understand this fully and get it as concise and correct as possible. 


xsl:value-of always returns the _string_ value of the node supplied in
its select attribute. (ie, teh concatenation of all the characers in its
descendants). If you supply a node set of more than one node, all but
the first node in document order will be discarded.

xsl:copy-of does a "deep copy" of its input, you can supply a value, or
a set of nodes, in its select attribute and all teh nodes/values will be

xsl:copy does a "shallow copy" it doesn't have a select attribute, and
for nodes without children (atributes/comments/processing instructions)
it does the same as copy-of, but for element nodes it just
generates an element node with the same name, without copying all
the child nodes. Typically you then use xsl:apply-templaes to generate
some new content that isn't a copy.

so if 

 <a>asd <b>ljh g</b> jhtg </a>
 <y>knv <b>asjfgq</b> oiacb </y>

and the current node is x then 

<xsl:value-of select="a|y"/>
"asd ljh g jhtg "

(characters in a, y is discarded)

<xsl:copy-of select="a|y"/>
 <a>asd <b>ljh g</b> jhtg </a>
 <y>knv <b>asjfgq</b> oiacb </y>
copy of those two elements


generates a (currently empty) node
in the result tree.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread