Subject: Re: [xsl] copying attributes to all child nodes From: "George Cristian Bina" <george@xxxxxxx> Date: Mon, 26 Jan 2004 14:16:42 +0200 |
Hi, This should get the expected output applied on your input document, however you may need to change it to adapt it to your actual needs as this assumes you want to get as output the first element that has an attributeX attribute with all it's cildren updated. Also it does not overwrite an attribute with the same name. If you want to overwrite attributeX values in children then replace <xsl:apply-templates mode="copy" select="@*"/> with <xsl:apply-templates mode="copy" select="@*[name() != 'attributeX']"/> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="*[@attributeX]"> <xsl:apply-templates select="." mode="copy"/> </xsl:template> <xsl:template match="*" mode="copy"> <xsl:copy> <xsl:attribute name="attributeX"><xsl:value-of select="//*/@attributeX"/></xsl:attribute> <xsl:apply-templates mode="copy" select="@*"/> <xsl:apply-templates mode="copy"/> </xsl:copy> </xsl:template> <xsl:template match="text()|@*" mode="copy"> <xsl:copy/> </xsl:template> <xsl:template match="*"/> </xsl:stylesheet> 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 1:04 PM Subject: [xsl] copying attributes to all child nodes > > > Hello > > I'm puzzling over a problem at the moment that has me stumped. I'm trying > to figure out a way to select a node based on an attribute, then copy that > attribute to all children of the node i.e. > > Sample XML > > <top.level.node attributeX="123456"> > <next element attributeXYZ="654321"> > <next2element> this is some text</next2element> > <next2element> this is some more text </next2element> > </nextelement> > </top.level.node> > > which I need to convert to > > <top.level.node attributeX="123456"> > <next element attributeXYZ="654321" attributeX="123456"> > <next2element attributeX="123456"> this is some > text</next2element> > <next2element attributeX="123456"> this is some more text > </next2element> > </nextelement> > </top.level.node> > > I have searched the FAQ, and the list archives, but I cant seem to find a > suitable way of doing it. Any help would be greatly appreciated. > > T. > > > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] copying attributes to all chi, Terence Mac Goff | Thread | Re: [xsl] copying attributes to all, Terence Mac Goff |
Re: [xsl] Contains - where containe, Mark Williams | Date | Re: [xsl] copying attributes to all, G. Ken Holman |
Month |