473,725 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ 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>(KiloWat ts)<\units>
<value>1.0<\val ue>
</energy>

Any ideas?

Thanks
Jul 20 '05 #1
2 2057
Tempore 22:50:17, die Wednesday 09 February 2005 AD, hinc in foro {comp.text.xml} scripsit plopez <plopez@spam_re movethis 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>(KiloWat ts)<\units>
<value>1.0<\val ue>
</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:styleshe et 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>(KiloWat ts)</units>
</xsl:template>

<xsl:template match="value[preceding-sibling::*[1]='(Watts)']">
<value><xsl:val ue-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>7 44</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:val ue-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.b e> wrote in message
news:op******** ******@news.pan dora.be...
Tempore 22:50:17, die Wednesday 09 February 2005 AD, hinc in foro
{comp.text.xml} scripsit plopez <plopez@spam_re movethis 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>(KiloWat ts)<\units>
<value>1.0<\val ue>
</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:styleshe et 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>(KiloWat ts)</units>
</xsl:template>

<xsl:template match="value[preceding-sibling::*[1]='(Watts)']">
<value><xsl:val ue-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
3641
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 gigabits/s or megabytes/s or gigabytes/s, whatever's the most useful (ala df -h)? Thanks!
14
2749
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
5258
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: http://geosoft.no/development/unittesting.html Thanks.
4
1502
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, however...it moves about as fast as a honda civic trying to tow a semi truck. The basic definition looks like this: public struct ScalarGeneric : IScalar
1
4332
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 valid.
1
3334
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 sending a command to a hardware device, and if it does not answer in the timeout defined (i.e. in 2 sec), my software fires an exception. Now, I am writing an unit test in which I start a timer and I send the command. Note that I DO expect an...
2
2377
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. Thanks, --Dean
1
3443
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 is. Here's a failure example: I created a simple little C# program called Test1. I added a new class that has a public method Sum, which does the brilliant function of adding two numbers together and returning the result. I added a unit test...
5
2246
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 if the module is run as a program. The PEP has status "Rejected", citing backward-compatibility issues, and Guido's pronouncement that "It's not worth the change (in docs, user habits, etc.) and there's nothing particularly broken."
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.