XSLT

Working with Lansa, I also have to maintain some WAMs. This entails quite a bit of XSLT, so today I needed to produce a formatted number, except when the value was zero.

I ended up with this, which is supported by the XSLT parser:

<xsl:transform>
 ...
 <!-- decimal-format 'cause I am danish -->
 <xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."
 NaN="" />
 ...
 <!-- sample call -->
 <xsl:call-template name="shoe_number2">
 <xsl:with-param name="numericvalue" select="$WPARDAG" />
 </xsl:call-template>
 ...
 <!-- templates -->
 <xsl:template name="shoe_number0">
 <xsl:param name="numericvalue" />
 <xsl:choose>
 <xsl:when test="$numericvalue = 0">
 </xsl:when>
 <xsl:otherwise>
 <xsl:value-of select="format-number(number(translate($numericvalue, ',', '.')), '###.###', 'euro')" />
 </xsl:otherwise>
 </xsl:choose>
 </xsl:template>
 <xsl:template name="shoe_number2">
 <xsl:param name="numericvalue" />
 <xsl:choose>
 <xsl:when test="$numericvalue = 0">
 </xsl:when>
 <xsl:otherwise>
 <xsl:value-of select="format-number(number(translate($numericvalue, ',', '.')), '###.###,00', 'euro')" />
 </xsl:otherwise>
 </xsl:choose>
 </xsl:template>
 <xsl:template name="shoe_index1">
 <xsl:param name="numericvalue" />
 <xsl:choose>
 <xsl:when test="$numericvalue = 0">
 </xsl:when>
 <xsl:otherwise>
 <xsl:value-of select="format-number(number(translate($numericvalue, ',', '.')), '#,0', 'euro')" />
 </xsl:otherwise>
 </xsl:choose>
 </xsl:template>
 <xsl:template name="shoe_index0">
 <xsl:param name="numericvalue" />
 <xsl:choose>
 <xsl:when test="$numericvalue = 0">
 </xsl:when>
 <xsl:otherwise>
 <xsl:value-of select="format-number(number(translate($numericvalue, ',', '.')), '#', 'euro')" />
 </xsl:otherwise>
 </xsl:choose>
 </xsl:template>
</xsl:transform>

Worked surprisingly well…

 

 


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s