[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Simple attribute value replacement question

Subject: RE: Simple attribute value replacement question
From: Edward.Middleton@xxxxxxxxxxx
Date: Tue, 29 Jan 2002 13:49:36 +0900
simple attribute
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.