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

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)" />
                  </xsl:call-template>
                </xsl:variable>


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



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




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

       </xsl:template>


  <xsl:template name="cut-leading-zeros">
    <xsl:param name="str"/>
    <xsl:choose>
      <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:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$str"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Open in new window


Thank you
Darius
DariusAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DariusAuthor Commented:
100% thanks Geert!
0
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.