xsl-list
[Top] [All Lists]

Re: Using a template to transform a node attribute

2005-09-12 08:32:44

But the parser tells me that I have a syntax error when trying to
specify the attribute "id" properly.  Any ideas?

It shouldn't be the parser (It's not a syntax error) You should have
(most likely) got a run time error saying that you could not generate an
attribute node (it depends on the rest of your template that you didn't
show). 

<xsl:template match="/report/version[(_at_)id]">

does not match id attributes it matches version elements that have an
id.

        <xsl:attribute name="id">bar</xsl:attribute>

then generates an id attribute but you may only do this if you have not
already started to generate child elements or text of the parent
element.

Probably you want something like

<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

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


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
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--