Re: [xsl] copying child nodes n-level deep

Subject: Re: [xsl] copying child nodes n-level deep
From: "Rob Lugt" <roblugt@xxxxxxxxx>
Date: Thu, 26 Jul 2001 17:13:40 +0100
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
>> 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
> 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

One solution is to make use of modes:-

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

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

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


 XSL-List info and archive:

Current Thread