【问题标题】:how to remove hyphen from string +xslt如何从字符串+xslt中删除连字符
【发布时间】:2016-07-20 13:21:06
【问题描述】:

如何从“19650512-0065”到“196505120065”等字符串中删除连字符

使用此模板:传递 ID =

   <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> 

【问题讨论】:

  • 尝试将 xsl:variable 和整个 xsl:choose 替换为 &lt;xsl:value-of select="translate($theID,'-','')"/&gt;
  • @DanielHaley 您应该将其作为答案而不是评论。
  • @MichaelKay - 当我无法测试它们时,我总是对添加答案持谨慎态度,尤其是通过我的手机,但我想这个很简单,我可以冒险:-)

标签: xslt substring hyphen


【解决方案1】:

尝试将xsl:variable 和整个xsl:choose 替换为:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    相关资源
    最近更新 更多