Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development

  • Print
  • + Share This
From the author of

From the author of

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 planets.xml, simply by copying only text and elements:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">

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

Here’s the output of this transformation:

<?xml version="1.0" encoding="UTF-8"?>

  • + Share This
  • 🔖 Save To Your Account