xsl-list
[Top] [All Lists]

[xsl] help needed with identity tranformation

2008-01-28 02:04:39
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>