[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] deep copy without attributes


Subject: Re: [xsl] deep copy without attributes
From: Ihe Onwuka <ihe.onwuka@xxxxxxxxx>
Date: Mon, 20 May 2013 15:00:24 +0100

On Mon, May 20, 2013 at 2:20 PM, G. Ken Holman
<gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
> At 2013-05-20 14:12 +0100, Ihe Onwuka wrote:
>>
>> I have done this
>>
>>   <xsl:template match="*">
>>     <pattern id="{@*[1]}">
>>       <xsl:copy>
>>         <xsl:apply-templates mode="no-attributes"/>
>>       </xsl:copy>
>>     </pattern>
>>   </xsl:template>
>>
>>   <xsl:template match="*" mode="no-attributes">
>>     <xsl:copy>
>>       <xsl:apply-templates mode="no-attributes"/>
>>     </xsl:copy>
>>   </xsl:template>
>>
>>
>> which seems cumbersome when what I really want to do is
>>
>>   <xsl:template match="*">
>>     <pattern id="{@*[1]}">
>>       <xsl:copy-of select="node() except @*"/>
>>     </pattern>
>>   </xsl:template>
>>
>> idea being to deep copy leaving the attribute nodes behind although
>> that syntax will not do that.
>
>
> Correct, because "node()" is an abbreviation for "child::node()" and you
> cannot find attributes along the child axis.
>
> And because your address is only looking at the child axis, there is no
> recursing down the depth of the tree.  You are asking for a lot of things to
> be different about the select= address you've written.
>

Please excuse the faux pas. It was made up syntax to hint at what i
wanted which is to have a copy-of that tosses all attributes while it
does it's deep copy.

> I'm not sure why you feel that adding single template rule is cumbersome.

well the first time I did it I got it wrong by forgetting to
recursively apply-templates mode='no-attributes'

I am loathe to call myself an experienced XSLT developer but the
solution given the circumstances would not be at all obvious to
someone of even less experience whereas, what is wanted is quite
simple. My opinion of course.

> And given the way you've written your template rule you can shorten the
> first template as follows:
>
>
>   <xsl:template match="*">
>     <pattern id="{@*[1]}">
>       <xsl:apply-templates select="." mode="no-attributes"/>
>     </pattern>
>   </xsl:template>
>

neat.


Current Thread
Keywords