473,473 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unit conversion problem.

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?

Thanks
Jul 20 '05 #1
2 2046
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
Jul 20 '05 #2
Thanks!!

It my real world problem was a little different.

<name>Cooling</name>
<units>(W)</units>
<binned_data type="monthly">
<index>0</index>
<steps>744</steps>
<active_steps>744</active_steps>
<sum>0.000000</sum>
</binned_data>
But you pointed me in the right direction!

It now my template looks like..
<xsl:template match="//sum[parent::*/preceding-sibling::units='(W)']">
<sum><xsl:value-of select="format-number(. div 1000,'#.0')"/></sum>
</xsl:template>
It probably would be better if I made the "units" value an attribute of
"sum". That way I could use a conversion table for all units and all
entities.

Thanks again!

PL

"Joris Gillis" <ro**@pandora.be> wrote in message
news:op**************@news.pandora.be...
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dan Stromberg | last post by:
Is there already a pure python module that can do modular-arithmetic unit conversions, like converting a huge number of seconds into months, weeks... or a bandwidth measure into megabits/s or...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
4
by: Stephan Rose | last post by:
In one of the applications I am developing I have need of working with numbers in varying unit system. I might be adding 5 mil to 1 inch or whatever. What I have come up with works really well,...
1
by: shapper | last post by:
Hello, In a custom control property I have the following: If CStr(ViewState("InfoWidth")) Is Nothing Then ... I am getting the error: Conversion from type 'Unit' to type 'String' is not...
1
by: batvanio | last post by:
Hi, I am writing unit tests in VS2005 and am having the following problem: I am trying to test a timeout property of one of my methods. This timeout exhibits itself in an exceptioin - i.e. I am...
2
by: Dean | last post by:
Is there a free js library for doing unit conversions? I am putting together an app that needs to convert volume and weight, among others. You'd think that one exists, but I have yet to find it....
1
by: Richard Lewis Haggard | last post by:
We're using VS05 and today the units tests have stopped working in our development environment. I'm sure that it is something really silly and simple but I'll be darned if I can figure out what it...
5
by: Ben Finney | last post by:
Howdy all, PEP 299 <URL:http://www.python.org/dev/peps/pep-0299details an enhancement for entry points to Python programs: a module attribute (named '__main__') that will be automatically called...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.