Link to home
Start Free TrialLog in
Avatar of tesmc
tesmcFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
simply put back what you have just taken away
only do the processing on the last component before you put it back
Avatar of tesmc

ASKER

thank you. that worked.