xsl-list
[Top] [All Lists]

Adding attributes to all ancestors of a given node (was RE: [xsl] XSL and javascript)

2003-03-12 12:11:33
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::*[(_at_)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



<Prev in Thread] Current Thread [Next in Thread>