Alessandro Melandri

Remove Leading Zeroes in XSL

Permalink

A useful XSL template for removing leading zeros

<xsl:template name="removeLeadingZeros">
<xsl:param name="originalString"/>
<xsl:choose>
<xsl:when test="starts-with($originalString,'0')">
<xsl:call-template name="removeLeadingZeros">
<xsl:with-param name="originalString">
<xsl:value-of select="substring-after($originalString,'0' )"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$originalString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Just insert it into your XSL file and use it as usual:

<xsl:call-template name="removeLeadingZeros">
<xsl:with-param name="originalString" select="$myOriginalString"/>
</xsl:call-template>