Subject: RE: [xsl] Simple attribute value replacement question From: Edward.Middleton@xxxxxxxxxxx Date: Tue, 29 Jan 2002 13:49:36 +0900 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Simple attribute value re, Andrew Welch | Thread | RE: [xsl] Simple attribute value re, Jeff Beadle |
Re: [xsl] lowercasing all attribute, Steve Ball | Date | RE: [xsl] FW: Path Reversal, Jarno . Elovirta |
Month |