Remove leading zeroes in XSL

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>

One Response

  1. RenĂ© • 11.12.09 @ 11.12

    Thanks, works like a charm!

Leave a Reply