|
Subject: Re: [xsl] help needed with identity tranformation From: Tony Graham <Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 28 Jan 2008 09:34:08 +0000 |
On Mon, Jan 28 2008 09:04:12 +0000, ericmutoniwabo@xxxxxxxxxxx wrote:
> Can some one help me with identity transformation?
...
> 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.
Saxon 8 gives this error message for your stylesheet.
XPST0003: XPath syntax error at char 1 on line 7 in {$4}:
expected "<name>", found "<numeric-literal>"
> 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?
The new '$4' that you want to insert is literal text, but the value of
the 'select' attribute is an expression to be evaluated, and '$4' is not
a valid expression.
This should do what you want:
------------------------------------------------------------
<?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()}">$4</xsl:element>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------------
(Or you could have been long-winded and used '<xsl:value-of
select="'$4'"/>' to make the expression be the string '$4'.)
Regards,
Tony Graham.
======================================================================
Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx http://www.menteithconsulting.com
Menteith Consulting Ltd Registered in Ireland - No. 428599
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
----------------------------------------------------------------------
Menteith Consulting -- Understanding how markup works
======================================================================
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] help needed with identity tra, ericmutoniwabo | Thread | [xsl] Using symbols for footnotes, Cindy Hunt |
| Re: [xsl] combining multiple docume, David Carlisle | Date | Re: [xsl] combining multiple docume, Steven Ericsson-Zeni |
| Month |