[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Using a template to transform a node attribute


Subject: Re: [xsl] Using a template to transform a node attribute
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 12 Sep 2005 17:00:08 +0100

> As written, this template matches an element node, so the attribute tag 
> would need to be wrapped in an element, as you indicate.

The template was perfectly valid as it stood. The element that contains
the attribute in the result tree does not have to be generated by the
same template as generates the attribute.

<xsl:template match="/report/version[@id]">
  <xsl:attribute name="id">bar</xsl:attribute>
</xsl:template>


<xsl:template match="/report/version/@id">
  <xsl:attribute name="id">bar</xsl:attribute>
</xsl:template>

Both have the same status. If they are triggerd by an apply-templates in
a context such as

<foo>
 <xsl:apply-templates select=",,,,,

Then they are OK, and add an id attribute to foo.

If they are triggered by a context such as

<foo>
 some text
 <xsl:apply-templates select=",,,,,

then they are an error as you can't add attribute after the text node
has been added.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


Current Thread