[xsl] help needed with identity tranformation

Subject: [xsl] help needed with identity tranformation
From: ericmutoniwabo@xxxxxxxxxxx
Date: Mon, 28 Jan 2008 09:04:12 +0000
Hi,

Can some one help me with identity transformation?

I have an XML file that I want to change few element values using
identity transformation and keeping the rest of the document unchanged.

here are samples of my xml and the xslt's

fruits.xml
<?xml version="1.0" encoding="UTF-8"?>
<fruit>
<orange>
<price>$2</price>
<color>yellow</color>
</orange>
<apple>
<price>$1</price>
<color>red</color>
</apple>
</fruit>


identity.xslt
<?xml version="1.0" encoding="UTF-8"?>
<!-- The Identity Transformation -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>


If I wanted to change for example the price of orange to $4 and
maintain the rest of the xml unchanged, how would I do that?

I want to change the "price" of "orange" to $4 for example. My logic is that I would
insert an element  "price" with value $4.
 I tried the xslt below without much success.


transform.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<!-- Import the identity transformation. -->
<xsl:import href="identity.xslt"/>
<xsl:template match="fruit/orange/price">
<xsl:element name="{name()}"><xsl:value-of select="$4"/></xsl:element>
</xsl:template>
</xsl:stylesheet>


I am using saxon as processor.
when I apply "transform.xslt" against "fruit.xml", the value of 
"fruit/orange/price" is not changing.
 I can't seem to match the element that I want to change the
value of.
Anyone sees what I am doing wrong?


Thanks, Eric.

Current Thread