Re: [xsl] Adding attributes

Subject: Re: [xsl] Adding attributes
From: Elizabeth Barham <soggytrousers@xxxxxxxxx>
Date: 07 Feb 2002 08:27:37 -0600
"Ivan Rubin Ayma" <Iayma@xxxxxxxxxxxx> writes:

> Suppose I had an XML:
> 
> <myelement type="10">
> 	<somedata/>
> </myelement>
> 
> and with the transformation I need to get:
> 
> <myelement type="10" color="blind">
> 	<somedata/>
> </myelement>

I'm supposing you mean something like this:

<xsl:template match="myelement[@type='10']">
  <myelement type="10" color="blind">
    <xsl:apply-templates />
  </myelement
</xsl:template>

In this example, the template only matches myelement's that have a
type equal to 10. OTOH, this would match 'myelement' and update
the element itself if and only if type = '10'

<xsl:template match="myelement">
  <myelement type="{@type}">
    <xsl:if test="@type='10'">
      <xsl:attribute name="color">
         blind
      </xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
  </myelement>
</xsl:template>

Elizabeth

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


Current Thread