Subject: RE: [xsl] Simple attribute value replacement question From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 29 Jan 2002 09:25:31 -0000 |
Hi, You could use: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="pet"> <xsl:copy> <xsl:attribute name="type">canine</xsl:attribute> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> Cheers andrew === -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Regina, Paul Sent: Monday, January 28, 2002 11:40 PM To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Simple attribute value replacement question Here is an overly simplified example of what I am trying to do. I want to convert from one XML to another, I am having trouble changing the attribute "type". It needs to go from the word "dog" to the word "canine": <?xml version="1.0"?> <petXML> <pet type="dog"> <color>black</color> </pet> </petXML> To: <?xml version="1.0"?> <animalXML> <pet type="canine"> <color>black</color> </pet> </animalXML> I thought this xsl would do it but apparently not: <?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"> <xsl:element name = "animalXML"> <xsl:apply-templates select = "*"/> </xsl:element> </xsl:template> <xsl:template match = "*"> <xsl:apply-templates select="@type"/> <xsl:copy-of select = "."/> </xsl:template> <xsl:template match="@type[.='dog']"> <xsl:value-of select="canine"/> </xsl:template> </xsl:transform> This is what I get: <?xml version="1.0"?><animalXML><pet type="dog"><color>black</color></pet></animalXML> Can someone please tell me where I am going wrong and how to do this? Thanks! XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Simple attribute value replac, Regina, Paul | Thread | RE: [xsl] Simple attribute value re, Edward . Middleton |
[xsl] saxon in batch file for lots , ronald heller | Date | RE: [xsl] Creating index headers, Michael Kay |
Month |