【发布时间】:2020-10-30 05:57:44
【问题描述】:
客户提供的 XML 在 XML 字符串中包含带有左大括号和右大括号的描述,我想使用 XSLT 1.0 拆分此字符串并显示为单个字符串。 XML 字符串:
<tempDescs> Loans and deposits schedules_Loans and deposits schedule details_List of Today\'s Entries(Authorised)_List of entries (unauthorised)_Forward entries (unauthorised)_Forward Entries by transaction_ </tempDescs>
代码:
<xsl:variable name="descs">
<xsl:call-template name="remove-parentheses">
<xsl:with-param name="string" select="$tempDescs"/>
</xsl:call-template>
</xsl:variable>
<xsl:template name="remove-parentheses">
<xsl:param name="string" />
<xsl:variable name="opb" select='"~Opb#"' />
<xsl:variable name="clb" select='"~Clb#"' />
<xsl:choose>
<!-- when open parenthesis is present remove it -->
<xsl:when test="contains($string, $opb)">
<xsl:value-of select="substring-before($string, $opb)" />
<xsl:call-template name="remove-parentheses">
<xsl:with-param name="string" select="substring-after($string, $opb)" />
</xsl:call-template>
</xsl:when>
<!-- when close parenthesis is present remove it -->
<xsl:when test="contains($string, $clb)">
<xsl:value-of select="substring-before($string, $clb)" />
<xsl:call-template name="remove-parentheses">
<xsl:with-param name="string" select="substring-after($string, $clb)" />
</xsl:call-template>
</xsl:when>
<!-- otherwise... -->
<xsl:otherwise>
<!-- ... just give the value of the string -->
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我在没有正确拆分右括号的情况下获得输出。
贷款和存款时间表_贷款和存款时间表详细信息_今天的条目列表授权)_未授权条目列表)未授权转发条目_按交易转发条目
我期待没有任何大括号的输出
贷款和存款时间表_贷款和存款时间表详细信息_今天的条目列表授权_条目未授权列表_转发条目未授权_转发条目按交易_
请帮忙
【问题讨论】: