|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Simple attribute value replacement question
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








