We help IT Professionals succeed at work.
Get Started

XSLT: how to rebuild a string separated by a delimiter

badtz7229 asked
Last Modified: 2015-09-22
I have the following string R/0R4/TEST/TEST AVAILABLE/R/12345678901234C1
I want to remove 1 digit from the string after the last "/" such that 1234567890123C1
I then want to rebuild the original string with the newValue such that: R/0R4/TEST/TEST AVAILABLE/R/1234567890123C1

I have the following below which shortens the last string by 1 digit. But I do not know how to rebuild it now.
<xsl:variable name="Num14">
  <xsl:call-template name="substring-after-last">
	<xsl:with-param name="input" select="$elem/Text" />
	<xsl:with-param name="marker" select="'/'" />

<xsl:variable name="Cpn" select="substring ( $Num14, 15, 2)"/>
<xsl:variable name="Num13" select="concat ( substring ( $Num14, 1, 13), $Cpn) "/>

  <xsl:template name="substring-after-last">
    <xsl:param name="input" select="''" />
    <xsl:param name="marker" select="''" />
        <xsl:when test="contains($input,$marker)">
          <xsl:call-template name="substring-after-last">
            <xsl:with-param name="input" select="substring-after($input,$marker)" />
            <xsl:with-param name="marker" select="$marker" />
          <xsl:value-of select="$input" />

Open in new window

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