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

Re: copying attributes to all child nodes

Subject: Re: copying attributes to all child nodes
From: "George Cristian Bina" <george@xxxxxxx>
Date: Mon, 26 Jan 2004 19:02:36 +0200
xsl copy attributes
Terence,

You can add a default copy template:

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

and match the exact elements you want the attribute added to in the copy
template that does also the attribute addition:

   <xsl:template match="next2element | next3element" mode="copy">
        <xsl:copy>
            <xsl:attribute name="attributeX"><xsl:value-of
select="//*/@attributeX"/></xsl:attribute>
            <xsl:apply-templates mode="copy" select="@*[name() !=
'attributeX']"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>

Best Regards,
 George
-------------------------------------------------------------
George Cristian Bina mailto:george@xxxxxxxxxxxxx
<oXygen/> XML Editor - http://www.oxygenxml.com/


----- Original Message -----
From: "Terence Mac Goff" <tmacgoff@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, January 26, 2004 6:00 PM
Subject: Re:  copying attributes to all child nodes


> Ken and George, thanks for both your great replies.
>
> I think I understand the process a bit better, and hopefully my
terminology
> will improve over time!
>
> One last question - If I wanted to get the attribute applied to only
> specific elements within the node, woudl I be better with a xsl:choose? or
> a select?
>
> <top.level.node attributeX="123456">
>          <next element attributeXYZ="654321">
>                  <next2element attributeX="123456"> this is some
> text</next2element>
>                  <next2element attributeX="123456"> this is some more text
> </next2element>
>          </nextelement>
> </top.level.node>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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.