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

RE: Correcting an XML document

Subject: RE: Correcting an XML document
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 16 Jul 2004 08:50:57 +0100
xslt copy xml document
>Is this neat little trick: 

	<xsl:copy><xsl:copy-of
select="@*"/><xsl:apply-templates/></xsl:copy> 

>in a book somewhere?  

Yes, it's on page 194 of my XSLT Programmer's Reference (and no doubt in
many other places - I didn't invent it!). It's called the "identity
template": not a very good name, because the result is an exact copy of the
original, but has different identity.

It sometimes appears in a different form:

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

And could you possibly explain it from the inside out? I had tried
xsl:copy-of, and I had considered xsl:copy, but I never considered putting
them both together.

In the form I gave it, it's a template rule that applies to every element;
it does a shallow copy of the element (i.e., copies the start and end tags),
uses copy-of to copy all the attributes unchanged, and then does
apply-templates to process the children, which will invoke the same template
rule recursively (for each one) unless there is an overriding rule.

The other variant (which appears in the XSLT spec itself) applies-templates
to the attribute nodes as well; the only difference is that you can then
write an overriding template rule for individual attribute nodes.

Michael Kay

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-2013 All Rights Reserved.