We help IT Professionals succeed at work.
Get Started

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

Darius asked
Last Modified: 2017-11-22
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
Information Architect
Top Expert 2006
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE