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

Adding attributes to all ancestors of a given node (wa

Subject: Adding attributes to all ancestors of a given node (was RE: XSL and javascript)
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Mar 2003 14:11:33 -0500
javascript adding attributes
Mac,

(I changed the thread)

You wrote:
        I am trying to simply duplicate an XML tree with the addition of
adding an attribute to all the ancestors of a given element.

That's a tip-off. This is an application of a near-identity transformation:


<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:if test="descendant::*[@task='1']">
      <xsl:attribute name="task">
         <!-- your attribute's value goes here -->
      </xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

It simply adds a 'task' attribute to any element that has a descendant with your criterion.

Since attributes have no descendants, it isn't a problem to handle them in the same template.

Since the template doesn't match the root node (q: why doesn't it?), we don't need to worry about it either (it'll be handled by default).

Cheers,
Wendell



___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_
    "Thus I make my own use of the telegraph, without consulting
     the directors, like the sparrows, which I perceive use it
     extensively for a perch." -- Thoreau


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread
  • RE: XSL and javascript, (continued)
    • Passin, Tom - Tue, 11 Mar 2003 16:09:22 -0500 (EST)
      • jeff - Tue, 11 Mar 2003 17:55:16 -0500 (EST)
    • Passin, Tom - Wed, 12 Mar 2003 12:16:53 -0500 (EST)
      • Mac Martine - Wed, 12 Mar 2003 13:03:02 -0500 (EST)
        • Wendell Piez - Wed, 12 Mar 2003 14:09:04 -0500 (EST) <=

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.