Possible Duplicate:
Formatting scientific number representation in xsl
I have an XML file which I'm hoping to format using XSLT and produce another XML file.
The input is like so:
<Sale>
<office>NY</office>
<origQty>2.0E7</origQty>
<shortQty>2.0E7</shortQty>
<price>0.0</price>
<qty>10000000</qty>
</Sale>
The XSLT reads as follows. Basically I'm trying to do a global copy and then work on the elements I choose:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"
indent="no" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="qty">
<xsl:copy>
<xsl:value-of select="qty"/>
</xsl:copy>
</xsl:template>
<xsl:template match="shortQty">
<xsl:value-of select="shortQty"/>
</xsl:template>
<xsl:template match="origQty">
<xsl:element name="origQty">
<xsl:value-of select="number(origQty) + 1"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
The current output I get is like so:
<Sale>
<office>NY</office>
<origQty>NaN</origQty>
<price>0.0</price>
<qty />
</Sale>
You can see I've been experimenting with different ways of capturing the data I want, with little success. The idea is to grab the quantities and then format them in my own way. So I'd like to:
- get the value of the element
- convert it to a number
- do some maths with it ( +1, div 1000, whatever)
- output it back to the XML
After researching this I thought number() was my best shot but as you can see that gives me NaN... Any advice as to what I should be doing here?
Thanks, Dave.