Alessandro Melandri

WebSphere Commerce Specialist, project manager, wannabe photographer

Remove Leading Zeroes in XSL

A useful XSL template for removing leading zeros

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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:

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