ConvertToCelsius Template

Jul 27, 2010 at 2:21 AM
Edited Jul 27, 2010 at 4:01 AM

Marc, I left the paramTrimmed within the template because of it's usage in the date_templates.xsl. I used that template, well as a template =), for this one. This template uses two parameters: paramTemp and AddNotation. paramTemp is the Fahrenheit temperature you need converted. AddNotation will append ºC to the temperature.

Usage:

<xsl:call-template name="ConvertToCelsius">
<xsl:with-param name="paramTemp" select="@DaysOfTask" />
<xsl:with-param name="AddNotation" select="'True'" />
</xsl:call-template>

Template:

<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
version="1.0"
exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:SharePoint="Microsoft.SharePoint.WebControls"
xmlns:ddwrt2="urn:frontpage:internal">

<!-- ConvertToCelsius -->
<xsl:template name="ConvertToCelsius">
<xsl:param name="paramTemp" />
<xsl:param name="AddNotation" />
<!-- trim extra spaces from input and convert to number -->
<xsl:variable name="paramTempTrimmed" select="normalize-space($paramTemp)" />
<!-- Coversion to Celsius -->
<xsl:choose>
<xsl:when test="$AddNotation = 'True'">
<xsl:value-of select="concat(format-number(((($paramTempTrimmed - 32) div 9) * 5), '#.##'),' ºC')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-number(((($paramTempTrimmed - 32) div 9) * 5), '#.##')" />
</xsl:otherwise>
</xsl:choose>
<!-- END TEMPLATE -->
</xsl:template>
</xsl:stylesheet>

Jul 27, 2010 at 2:23 AM
This looked a whole lot better before I posted it...
Jul 29, 2010 at 2:43 PM

I've noticed a bit of a bug and I'd like to see if it's just here or not.  If the Fahrenheit value is 32 degrees, the conversion doesn't display a value.  Can someone test that to confirm?

Coordinator
Jul 30, 2010 at 3:53 AM

Matt:

I tested the template as posted and made sure it worked the way I expected. I did have to tweak a little, but it was tweaks on top of my initial tweaks to your code.
http://spxslt.codeplex.com/wikipage?title=ConvertToCelsius

M.