【发布时间】:2016-04-30 22:06:12
【问题描述】:
我有如下的 XML 文件,
<sec>
<para>Section 1- TOC</para>
<para>Section 4* Main</para>
<para>Section 3$ Basic content</para>
<para>Section 11_ Section 10</para>
<para>Section 15@ Appendix 6</para>
</sec>
我需要使用函数在text() 节点中获取数字后跟“Section”字符串。
示例:
<xsl:function name="abc:get-section-number">
<xsl:param name="string" as="xs:string"/>
<xsl:sequence select="tokenize($string,'\d+')[1]"/>
</xsl:function>
这个例子返回数字之前的子字符串,但是我需要在'Section'字符串之后获取数字值..(输出值应该是1,4,3,11和15)
我尝试了一些内置函数(string-before、strong-after、matches..),但找不到任何合适的解决方案。
谁能给我一个方法来获得这个数值?
【问题讨论】:
-
检查this answer。你似乎只需要
Section\s+(\d+)。然后<xsl:value-of select="regex-group(1)"/>