XSL copy-of and value-of

Like most languages there are often a variety of ways of achieving similar results, and XSL is no different.

Take the xsl copy-of and value-of commands.

Assuming the following sample xml document:

<xml>
<text>Good <b>news</b> everybody!</text>
</xml>

The following uses of copy-of and value-of all achieve similar but different results.

copy-of

<xsl:copy-of select="/xml/text" />
<text>Good <b>news</b> everybody!</text>

Using node()

<xsl:copy-of select="/xml/text/node()" />
Good <b>news</b> everybody!

Using *

<xsl:copy-of select="/xml/text/*" />
<b>news</b>

value-of

<xsl:value-of select="/xml/text" />
Good news everybody! 

About

This is the personal blog of Adrian Lynch, owner of Millstream, developers of Spring CMS.

Version: 1.3