tags:

views:

100

answers:

3

Hi,

I am new to XSLT and need to know how to convert a fahrenheit value to celsius value.

Thanks,

+7  A: 

You can use formulas, providing that x is an XPath query to the fahrenheit value:

<xsl:value-of select="(x - 32) * 5 div 9" />

Also see Math and XSLT.

I grabbed the conversion formula from Wikipedia

Sander Rijken
+3  A: 

Having xml like

<degrees>
  <value>0</value>
</degrees>

You can use

<xsl:template match="degrees">
   <xsl:value-of select="(value - 32) div 1.8"/>
</xsl:template>
Li0liQ
A: 

Well, you would start with the formula to do it, something like

Celsius = 100 /(212-32) * (Farenheit - 32)

Now, assuming you have an xml document which contains a bunch of F values which you want to convert - such as:

<temperatures>
  <temperature>10</temperature>
  <temperature>20</temperature>
  <temperature>30</temperature>
</temperatures>

you can use

<xsl:template match="temperatures">
   <xsl:value-of select="100 div (212-32) * (temperature - 32)"/>
</xsl:template>
Jamiec