This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Simple attribute value replacement question
- From: Edward dot Middleton at nikonoa dot net
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 29 Jan 2002 13:49:36 +0900
- Subject: RE: [xsl] Simple attribute value replacement question
- Reply-to: xsl-list at lists dot mulberrytech dot com
There are two mistakes
1.
<xsl:value-of select="canine">
gets the value of the canine attribute which doesn't exist so it returns nothing.
You only have a dog attribute and you are not interested in its value you want to set it so you should use
<xsl:attribute name="type">canine</xsl:attribute>
2.
you don't copy the <pet> before you try to add an attribute to it. In your example it is actually copied by
<xsl:copy-of select = "."/>
which occurs after you have tried to set the type attribute. The following uses xsl:copy to copy pet.
<pet>
<xsl:apply-templates select="@type"/>
<xsl:copy-of select = "child::*"/> -- you use child::* because you have allready
copied the current tag i.e. pet
</pet>
The following should work.
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:transform xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
version = "1.0">
<xsl:template match = "petXML">
<animalXML>
<xsl:apply-templates select = "*"/>
</animalXML>
</xsl:template>
<xsl:template match = "pet">
<pet>
<xsl:apply-templates select="@type"/>
<xsl:copy-of select = "child::*"/>
</pet>
</xsl:template>
<xsl:template match="@type[.='dog']">
<xsl:attribute name="type">canine</xsl:attribute>
</xsl:template>
</xsl:transform>
Edward
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list