xsl-list
[Top] [All Lists]

RE: XSLT - update attribute with new value

2004-11-08 08:43:23
Hi,

Now I have one final question. I want to add an attribute/value to the
xml tree only if that attribute does not exist anywhere in 
the document
source tree.

Is there a way to do that in XSLT?

<xsl:template match="the-node-to-add-the-attribute-to">
  <xsl:copy>
    <xsl:if test="not(//@the-attribute)">
      <xsl:attribute name="the-attribute">the value</xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

Cheers,

Jarno