convert xml weather data from fahrenheit to celsius

hello, i would like to knwo if someone has some experience in converting xml weather data that comes in fahrenheit to its equivalent in celsius.

The conversion formula is Tc = (5/9)*(Tf-32);

Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit

Using the above formula, you would first subtract 32 from the Fahrenheit temperature and get 66.6. Then you multiply 66.6 by five-ninths and get 37 degrees Celsius.

I got a xslt template that displays the weather data, but currently only displays fahrenheit.
Could someone, if possible tech me how to do the conversion inside the xsl template, or if this is even possible?

Thank you so much!

here is the template:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/current-conditions/reporting-station"/>
<xsl:if test="not(/seven-day-forecast/reporting-station)">
      <xsl:apply-templates select="/three-day-forecast/reporting-station"/>
</xsl:if>
<xsl:apply-templates select="/zone-forecast/reporting-station"/>
</xsl:template>

<xsl:template match="/three-day-forecast/reporting-station">
<three-day-forecast>
<table class="SectionTitle" border="0" width="100%">
    <tr>
        <td valign="top">3-Day Forecast</td>
        <td align="right"><script language="javascript" src="http://ads.myadmanager.com/adserver/per=contextual/id=hello"></script></td>
    </tr>
    <tr>
        <td colspan="2"><img src="Images/graydot.gif" border="0" height="1" width="100%" vspace="0"/></td>
    </tr>
</table>
<table class="FivedayForecast" border="0" width="100%">
<tr>
<xsl:apply-templates select="forecast-day[position()&lt;=7]"/>
</tr>
</table>
</three-day-forecast>
</xsl:template>

<xsl:template match="forecast-day">
<td class="Day">
    <table border="0">
        <tr>
            <td width="20%" class="Day"><xsl:value-of select="day"/></td>
        </tr>
        <tr>
            <td width="20%" class="Icon"><img src="{icon-name}"/></td>
        </tr>
        <tr>
            <td width="20%" class="Condition"><xsl:value-of select="sky-conditions"/></td>
        </tr>
        <tr>
            <td width="20%" class="Temp"><span class="High"><xsl:value-of select="high"/>&#176;</span> / <span class="Low"><xsl:value-of select="low"/>&#176;</span></td>
        </tr>
    </table>
</td>
</xsl:template>

<xsl:template match="/current-conditions/reporting-station">
<location>
<table>
    <tr>
        <td class="LocationTitle"><xsl:value-of select="city"/>, <xsl:value-of select="state"/></td>
    </tr>
</table>
</location>

<current-conditions>
<table class="SectionTitle" border="0" width="200">
    <tr>
        <td>Current Conditions<br/><img src="Images/graydot.gif" border="0" height="1" width="100%" vspace="0"/></td>
    </tr>
</table>
<table class="CurrentConditions" border="0" width="200">
    <tr>
        <td colspan="2" class="DateTime"><xsl:value-of select="../date"/>, <xsl:value-of select="../time"/></td>
    </tr>
    <tr>
        <td colspan="2" class="Label"><SPAN class="MediumData"><xsl:value-of select="sky-conditions"/></SPAN></td>
    </tr>
    <xsl:if test="temperature!=''">
        <tr>
            <td class="Label">Temperature</td>
            <td class="Data"><xsl:value-of select="temperature"/>&#176;</td>
        </tr>
    </xsl:if>
    <xsl:if test="dew-point!=''">
        <tr>
            <td class="Label">Dew Point</td>
            <td class="Data"><xsl:value-of select="dew-point"/>&#176;</td>
        </tr>
    </xsl:if>
    <xsl:if test="wind-chill!=''">
        <tr>
            <td class="Label">Wind Chill</td>
            <td class="Data"><xsl:value-of select="wind-chill"/>&#176;</td>
        </tr>
    </xsl:if>
    <xsl:if test="heat-index!=''">
        <tr>
            <td class="Label">Heat Index</td>
            <td class="Data"><xsl:value-of select="heat-index"/>&#176;</td>
        </tr>
    </xsl:if>
    <xsl:if test="relative-humidity!=''">
        <tr>
            <td class="Label">Humidity</td>
            <td class="Data"><xsl:value-of select="relative-humidity"/>%</td>
        </tr>
    </xsl:if>
    <xsl:if test="precip-today!=''">
        <tr>
            <td class="Label">Precip. Today</td>
            <td class="Data"><xsl:value-of select="precip-today"/> in.</td>
        </tr>
    </xsl:if>
    <xsl:if test="wind-direction!=''">
        <tr>
            <td class="Label">Wind</td>
            <td class="Data"><xsl:value-of select="wind-direction"/><xsl:if test="wind-speed!=''"> at <xsl:value-of select="wind-speed"/> mph</xsl:if></td>
        </tr>
    </xsl:if>
    <xsl:if test="altimeter!=''">
        <tr>
            <td class="Label">Barometer</td>
            <td class="Data"><xsl:value-of select="altimeter"/> in. <xsl:if test="pressure-tendency!=''"> <xsl:value-of select="pressure-tendency"/></xsl:if></td>
        </tr>
    </xsl:if>
    <xsl:if test="visibility!=''">
        <tr>
            <td class="Label">Visibility</td>
            <td class="Data"><xsl:value-of select="visibility"/> mi.</td>
        </tr>
    </xsl:if>
</table>
</current-conditions>
</xsl:template>
</xsl:stylesheet>
                                    
itortuAsked:
Who is Participating?
 
mshogrenCommented:
oops, I forgot the correct division operator for XSL.  Try

<xsl:value-of select="(5 div 9) * (number(temperature) - 32)"/>
0
 
mshogrenCommented:
Assuming that the temperature is already numeric, you should be able to replace

<xsl:value-of select="temperature"/>

with

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

0
 
itortuAuthor Commented:
hi mshogren, first of all thank you for your help.

i tried your suggestion and change this line:
       
        <xsl:if test="temperature!=''">
            <tr>
                <td class="mywx-Label">Temperature</td>
                <td class="mywx-Data"><xsl:value-of select="temperature"/>&#176;</td>
            </tr>
        </xsl:if>

to make it like this:

        <xsl:if test="temperature!=''">
            <tr>
                <td class="mywx-Label">Temperature</td>
                <td class="mywx-Data"><xsl:value-of select="(5/9) * (number(temperature) - 32)"/>&#176;</td>
           </tr>
       </xsl:if>

and when i run the page i got this error: error= 80004005 (Unspecified error) - msxml3.dll Expression does not return a DOM node. (-->5/<--9) * (number(temperature) - 32)

any ideas why?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
itortuAuthor Commented:
actually the complete error is this:

Error retrieving XML data in default.asp
Error number: N/A
200 - HTML: COM error= 80004005 (Unspecified error) - msxml3.dll Expression does not return a DOM node. (-->5/<--9) * (number(temperature) - 32)


the asp page default seems to be expecting some type of node, but the formula is returning not a DOm node, can this be fixed without altering the .asp page?
0
 
itortuAuthor Commented:
this is the xml file i am using:

&#8722;<three-day-forecast gmt="1148589705" gmt-offset="-5">
<date>Thursday, May 25</date>
<dateabbr>05/25/06</dateabbr>
<time>04:05 PM CDT</time>
&#8722;<reporting-station code="EDDI">
<city>Berlin</city>
<state>Germany</state>
&#8722;<forecast-day>
<day>Thursday</day>
<high>61</high>
<low>42</low>
<icon-select>10</icon-select>
<sky-conditions>Rain</sky-conditions>
</forecast-day>
&#8722;<forecast-day>
<day>Friday</day>
<high>60</high>
<low>43</low>
<icon-select>3</icon-select>
<sky-conditions>Partly cloudy</sky-conditions>
</forecast-day>
&#8722;<forecast-day>
<day>Saturday</day>
<high>63</high>
<low>42</low>
<icon-select>10</icon-select>
<sky-conditions>Rain</sky-conditions>
</forecast-day>
</reporting-station>
</three-day-forecast>
0
 
itortuAuthor Commented:
i think is not a problem with the asp page, i just made a simple page to load the xml and the xsl, and still got the same error.
0
 
itortuAuthor Commented:
i hope you someone can offer some help.

thanks
0
 
itortuAuthor Commented:
i think my problem is related to xpath. please some help : )
0
 
itortuAuthor Commented:
ahhh, that worked very well!

you know something, after doing the conversion, the numbers in celsius are returned in this format: 12.222222222222223°

is there any function to round it up so it does not show the decimals?

thank you very much.
0
 
itortuAuthor Commented:
how can i use the format-number inside this part:

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

?
0
 
mshogrenCommented:
You don't need to use format-number though you can if you like.  I would use round() like this:

<xsl:value-of select="round((5 div 9) * (number(wind-chill)- 32))"/>
0
 
itortuAuthor Commented:
ideally i would like to see the degree number in this format: 99
and not 99.99 neither 99.9999999

by using the round method, would then the decimal places willl be omitted?

thanks!

0
 
mshogrenCommented:
If you just want to remove the decimal places rather an round to the nearest integer use floor().  It shouldn't take long to try both out and see whihc one gives preferable results.

<xsl:value-of select="floor((5 div 9) * (number(wind-chill)- 32))"/>
0
 
itortuAuthor Commented:
Thank you very much mshogren!
I have another question posted, but I have not receive any comments yet, it is xml related, and if you have the time may be you can help me with my problem.

once again thank you very much for your help on this question!

here is the link to my other question:

http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21862991.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.