xsl-list
[Top] [All Lists]

Re: [xsl] help needed with identity tranformation

2008-01-28 02:34:55
On Mon, Jan 28 2008 09:04:12 +0000, ericmutoniwabo(_at_)comcast(_dot_)net 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(_dot_)Graham(_at_)MenteithConsulting(_dot_)com   
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
======================================================================

--~------------------------------------------------------------------
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>