Search code examples
xsltsubstring

how to remove hyphen from string +xslt


how to remove hyphen from string like "19650512-0065" to "196505120065"

using this template : passing theID =

   <xsl:template name="unformatLFPartyID">
        <xsl:param name="theID" select="." />

        <xsl:variable name="idSuffix" select="string-length($theID) - 3" />

        <xsl:choose>
            <xsl:when test="contains($theID,'-')">
                <xsl:value-of select="substring($theID,0,$idSuffix)" />
                <xsl:value-of select="substring($theID, $idSuffix)" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$theID" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template> 

Solution

  • Try replacing the xsl:variable and entire xsl:choose with:

    <xsl:value-of select="translate($theID,'-','')"/>