You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用XSLT 1.0从大文本中提取数值500?

使用XSLT 1.0提取文本中的errorCode值

如果要从包含"o:errorCode" : "500"的大文本中提取数字500,由于XSLT 1.0没有原生正则支持,可通过字符串截取函数组合实现:

核心实现代码

假设待处理文本位于<source-text>节点中,对应的XSLT模板如下:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />

  <xsl:template match="source-text">
    <!-- 截取"o:errorCode" : "之后的字符串片段 -->
    <xsl:variable name="post-code-prefix" select="substring-after(., '&quot;o:errorCode&quot; : &quot;')" />
    <!-- 截取上述片段中第一个双引号之前的内容,即目标数字 -->
    <xsl:variable name="error-code" select="substring-before($post-code-prefix, '&quot;')" />
    <!-- 输出提取到的错误码 -->
    <xsl:value-of select="$error-code" />
  </xsl:template>
</xsl:stylesheet>

注意事项

  • XSLT中双引号需要转义为&quot;,若原文本使用单引号,需将代码中的&quot;替换为&apos;。
  • 上述代码仅提取第一个匹配的o:errorCode对应值,若文本中存在多个匹配项,可通过递归模板遍历所有匹配位置来提取。

内容的提问来源于stack exchange,提问作者MOz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 19:05:20