xslt 1.0 - Formatting string  (Substrings from the End of a String)

Darius used Ask the Experts™
Hi guys,

Please assist with this validation.
Have an issue to substring from the End of a String.
Please see below

           <xsl:variable name="originalValue" select="'[some Values]'" />

                <xsl:variable name="valueUpdated">
                  <xsl:call-template name="cut-leading-zeros">
                    <xsl:with-param name="str" select="normalize-space($originalValue)" />

                <!-- If original values does not have leading zeros
                 . . .
                  concat orginal value with prefix 'BX' 
                <xsl:if test="$originalValue">
                  <xsl:value-of select="concat('BX', $originalValue)"/>

                <!-- If updated values after removed leading zeros greather then 18
                  . . .
                  concat updated value with prefix 'BX' 
                <xsl:if test="string-length($valueUpdated) &gt; 18">
                  <xsl:value-of select="concat('BX', $valueUpdated)"/>

                <!-- If original values after removed leading zeros less then 18
                  . . .
                  substring from the End of a String to 18 digits
                  and concat value with prefix 'BX' 
                  expect values:
                <xsl:if test="string-length($valueUpdated) &lt; 18">
                  <!--max length 20:  'BX' and value-->
                  . . . to do . . .


  <xsl:template name="cut-leading-zeros">
    <xsl:param name="str"/>
      <xsl:when test="substring($str, 1, 1) = '0'">
        <xsl:call-template name="cut-leading-zeros">
          <xsl:with-param name="str" select="substring($str, 2)"/>
        <xsl:value-of select="$str"/>

Open in new window

Thank you
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
If I understand well enough what you need....
you need a 18 character long string to follow BX.... padded with zeros

you could have a variable zeroes
<xsl:variable name="zeroes" select="'00000000000000000000'"/>
with 20 zero characters in there
now you can take a
<xsl:value-of select="concat('BX', substring($zeroes, 1, 18 - string-length($valueUpdated) ,$valueUpdated)"/>
should work


100% thanks Geert!
Gertone (Geert Bormans)Information Architect
Top Expert 2006


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial