XSLT: how to rebuild a string separated by a delimiter

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

<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:choose>
        <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:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$input" />
        </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

Open in new window

badtz7229Asked:
Who is Participating?
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.

Geert BormansInformation ArchitectCommented:
You could simply reconstruct whilst you are at it

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="1.0">
    
    <xsl:variable name="input-str">R/0R4/TEST/TEST AVAILABLE/R/12345678901234C1</xsl:variable>
    
    <xsl:template match="/">
        <xsl:call-template name="process-last-component">
            <xsl:with-param name="input" select="$input-str" />
            <xsl:with-param name="marker" select="'/'" />
        </xsl:call-template>
    </xsl:template>
    
    <xsl:template name="process-last-component">
        <xsl:param name="input" select="''" />
        <xsl:param name="marker" select="'#'" /><!-- it is dangerous to make the default marker empty -->
        <xsl:choose>
            <xsl:when test="contains($input, $marker)">
                <xsl:value-of select="substring-before($input, $marker)"/>
                <xsl:value-of select="$marker"/>
                <xsl:call-template name="process-last-component">
                    <xsl:with-param name="input" select="substring-after($input, $marker)" />
                    <xsl:with-param name="marker" select="'/'" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring ( $input, 1, 13)"/>
                <xsl:value-of select="substring ( $input, 15)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
 
    
    
</xsl:stylesheet>

Open in new window

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
Geert BormansInformation ArchitectCommented:
simply put back what you have just taken away
only do the processing on the last component before you put it back
0
badtz7229Author Commented:
thank you. that worked.
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
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.