Tempore 22:50:17, die Wednesday 09 February 2005 AD, hinc in foro {comp.text.xml} scripsit plopez <plopez@spam_removethis crazy remove.nrcan.gc.ca>:
Hi
I'm a bit of a noob to xslt. I have a data.xml document like this..
input.xml
<energy>
..lots and lots of other data....
<units>(Watts)<\units>
<value>1000.0<\value>
</energy>
Now I want to have an xslt stylesheet that will convert it from watts to
kilowatts.
output.xml
<energy>
..lots and lots of other data.....
<units>(KiloWatts)<\units>
<value>1.0<\value>
</energy>
Any ideas?
Hi,
You'll need a conversion table in XML.
Now if only Google would output XHTML...
http://www.google.com/search?q=1000....29+in+kilowatt
If the watt->kilowatt is really the only conversion, you can use:
<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:template match="units[.='(Watts)']">
<units>(KiloWatts)</units>
</xsl:template>
<xsl:template match="value[preceding-sibling::*[1]='(Watts)']">
<value><xsl:value-of select="format-number(. div 1000,'#.0')"/></value>
</xsl:template>
</xsl:stylesheet>
regards,
--
Joris Gillis (
http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple