tags:

views:

219

answers:

3

Hi,

I have XML file with values expressed in SI unit (m, N). I use an XSLT document to transform it into HTML page where I would like to display values with other units (um, mN).

Is there a way to modify values I extract from my XML document using XSLT without modifying XML content before XSLT processing ?

Thanks in advance for your help

Bertrand

+4  A: 

You can do math in XPath expressions:

<!-- divide somevalue by 1000 --> 
<xsl:value-of select="somevalue div 1000.0" />
Tomalak
Looks perfect. Do exactly what I want.Thanks
Bertrand
A: 

If you were using c# to run the xslt transform, and the maths capabilities of Xpath are not good enough for your requirements, you can make calls from the xslt to methods in your c# class which would allow you to call out to c# to do your maths and then return the value back into your xslt. Search for c# xslt extensions.

Si Keep
Will have a look to XSLT extensions.
Bertrand
And while you're at it, bind the C# to an external web service that calls google's calculator api through an enterprise service bus...
Pete Kirkham
Thanks for that Pete, I was merely pointing out an option, not suggesting it was the 'right' answer in this case.
Si Keep
Extensions can be helpful for date parsing and reformatting - there are XSLT stylesheets out there for date processing, but what can be done in 5 lines of C# is humongous in XSLT.
ijw
A: 

Just to notice to others interesting in. I'm developing in Python, and lxml library allow you to call extensions in XSLT.

http://codespeak.net/lxml/extensions.html

Bertrand
Clarification and extra info (like this) should go right to the question (you can always edit your own posts). The answers section should contain actual answers only.
Tomalak