选择取决于上下文的子字符串

时间:2013-04-30 14:41:40

标签: xslt

我有这段XML,想在Chapter

之后立即得到这个数字
<para>Insolvency Rules, r 12.12, which gives the court a broad discretion, unfettered by the English equivalent of the heads of Order 11, r 1(1) (which are now to be found, in England, in CPR, Chapter 6, disapplied in the insolvency context by Insolvency Rules, r 12.12(1)). </para>

当我使用这个XSLT转换时

<xsl:value-of select="translate(substring-after(current(),'Chapter'), translate(substring-after(current(),'Chapter'),'0123456789',''), '')"/>

我得到了这个输出

612121

Butut我只想6

请告诉我应该怎么做。

我不想使用像

这样的陈述
<xsl:value-of select="substring-before(substring-after(current(),'Chapter'), ,',')"/>

因为章节编号在每种情况下都会有所不同,介于1和15之间。

1 个答案:

答案 0 :(得分:1)

试试这个:

    <xsl:variable name="vS" select="concat(substring-after(current(),'Chapter '),'Z')"/>
    <xsl:value-of select=
           "substring-before(translate($vS,translate($vS,'0123456789',''),'Z'),'Z')"/>

这基于:https://stackoverflow.com/a/4188249/2115381谢谢 @Dimitre Novatchev

更新:如果“章节”之后的空间数量未知,您可以使用以下内容:

<xsl:variable name="vS" select="concat(substring-after(current(),'Chapter'),'Z')"/>

<xsl:value-of select=
        " translate(
        substring-before(translate($vS,translate($vS,' 0123456789',''),'Z'),'Z')
     , ' ','')"/>