O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Copying Nodes

You can use the <xsl:copy> element to copy nodes, specifying just what parts you want to copy. The default rule for elements is that only the text in the element is copied. However, you can change that with <xsl:copy>, which can copy whole elements, text nodes, attributes, processing instructions, and more, as you direct.

Here's an example. In this case, I'll strip all comments, processing instructions, and attributes out of ch13_01.xml, simply by copying only text and elements:

Listing . ch13_23.xsl
 
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="* | text()">
    <xsl:copy>
					<xsl:apply-templates select="* | text()"/>
					</xsl:copy> </xsl:template> </xsl:stylesheet> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required