XSLT将华氏温度转换为摄氏温度

时间:2009-12-22 13:50:58

标签: xml xslt

我是XSLT的新手,需要知道如何将华氏温度值转换为摄氏温度值。

谢谢,

3 个答案:

答案 0 :(得分:7)

您可以使用公式,前提是x是对华氏值的XPath查询:

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

另见Math and XSLT

我从Wikipedia

抓取转换公式

答案 1 :(得分:3)

像xml一样

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

您可以使用

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

答案 2 :(得分:0)

好吧,你可以从公式开始,比如

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

现在,假设您有一个包含要转换的一堆F值的xml文档,例如:

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

你可以使用

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