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

RE: copy XML and add attributes to ancestors of given

Subject: RE: copy XML and add attributes to ancestors of given element
From: Americo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Mar 2003 19:53:26 -0000
xsl copy of add attributes
Hi Mac.


> -----Mensagem original-----
> De: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] Em nome de Mac Martine
> Enviada: quarta-feira, 12 de Marco de 2003 18:13
> Para: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Assunto:  copy XML and add attributes to ancestors of 
> given element
> 
> 
> 
(...)
> Hello-
>  	I am trying to simply duplicate an XML tree with the 
> addition of adding an attribute to all the ancestors of a 
> given element.
> 
> 	In the example provided I am trying to copy all 
> elements, but when I find an element where @task='1', I want 
> to give all of its ancestors an attribute called 'task' as 
> well. My current code is below.
>  

Try this:

 <xsl:template match="*">
  <xsl:copy>
   <xsl:copy-of select="@*"/>
   <xsl:apply-templates select="descendant::*[@task=1]/@task"/>
   <xsl:apply-templates select="*"/>
  </xsl:copy>
 </xsl:template>
 
 <xsl:template match="@task">
 <xsl:attribute name="task">1.1</xsl:attribute>
 </xsl:template>

The <xsl:apply-templates select="descendant::*[@task=1]/@task"/> will do
nothing if ther is no descendant::*[@task=1]/@task

You could also use <xsl:apply-templates
select="descendant::*/@task[.=1]"/> but I find the first easy to read
and understand

Hope that this helps you


 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.