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

Re: copying child nodes n-level deep

Subject: Re: copying child nodes n-level deep
From: "Rob Lugt" <roblugt@xxxxxxxxx>
Date: Thu, 26 Jul 2001 17:13:40 +0100
xsl copy child nodes
Ram Anantha wrote


>> If you want to perform a deep copy (all elements and their children), use
>> <xsl:copy-of> as opposed to <xsl:copy> which only copies the current
>> element.  Selecting the grand-children of the current node can be
performed
>> simply with a concatenation of two child::* axis specifiers:-
>>
>> <xsl:template match="B">
>>  <xsl:copy-of select="child::*/child::*"/>
>> </xsl:template>
>
> ----------------------------------
> Thanks, Rob for your response.
>
> What should I change if I need to make a deep-copy of everything except
the
> attributes? Can I still use xsl:copy-of?
>

Ram, rather than replying to individual posters please reply to the list
with follow-up questions, and try to specify your original question as
precisely as possible.

If you don't want attributes then the problem is a little more difficult.
You can't make use of <xsl:copy-of> so you'll have to use recursion.  You
don't want to make use of the built-in template for elements because that
only copies the text value of the element.  Also, you don't want to replace
the built-in template for elements because then you will copy all and
sundry.

One solution is to make use of modes:-

<xsl:template match="B">
 <xsl:apply-templates mode="copy" select="child::*/child::*"/>
</xsl:template>

<xsl:template match="*" mode="copy">
 <xsl:copy>
   <xsl:apply-templates mode="copy"/>
 </xsl:copy>
</xsl:template>

In this way you decide at what branch to start the recursive copy, and you
avoid the built-in template.

Regards
~Rob



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.