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

SaxonHE12-5J报FORG0006错误,请求排查XPath表达式问题

问题排查:XSLT中FORG0006类型错误解决

错误信息

transform.xsl第243行第119列出现类型错误:
FORG0006 无法为包含两个或更多项且以布尔值开头的序列定义有效布尔值
调用链:transform.xsl第243行匹配"table[preceding-sibling::div[@class='sectionclass'][1]/text()[1]='Physical Properties:']/tbody"的模板规则,由内置模板规则(仅文本)触发;该模板规则又由transform.xsl第125行匹配"table[@class='cheminfo'][1]"的模板规则通过xsl:apply-templates调用(省略尾调用),路径为file:/home/pyork/Entwicklung/XSLT/Textknoten-Extraktion/Duftwerk/./transform.xsl#113

相关代码片段

<!-- Line 125 -->
<xsl:template match="table[@class='cheminfo'][1]">

<!-- Line 243 -->
<xsl:template match="table[preceding-sibling::div[@class='sectionclass'][1]/text()[1]='Physical Properties:']/tbody">

配置与调用命令

Saxon配置文件(saxon.config)

<configuration xmlns="http://saxon.sf.net/ns/configuration">
  <global
    generateByteCode="false"
  /> 
</configuration>

调用命令

java -jar ../../Tools/SaxonHE12-5J/saxon-he-12.5.jar \
-s:"transform-input-file-list.xml" \
-xsl:./transform.xsl \
-o:"transform-output.xml"
-config:"saxon.config"

问题分析与解决

问题根源

FORG0006错误的核心是:XPath谓词中使用了包含多个布尔值的序列,而非单个布尔值。原表达式preceding-sibling::div[@class='sectionclass'][1]/text()[1]='Physical Properties:'可能返回多个布尔值(比如当preceding-sibling::div[@class='sectionclass'][1]匹配多个节点,或文本节点比较时生成了布尔值序列),导致无法转换为有效的单个布尔判断条件。

修复方案

调整XPath表达式,确保谓词返回单个布尔值,以下是几种可行方式:

  1. 调整节点筛选逻辑:先定位目标div,再判断其文本内容,避免生成布尔值序列
<xsl:template match="table[preceding-sibling::div[@class='sectionclass'][1][text()[1]='Physical Properties:']]/tbody">
  1. 用boolean()函数强制转换为单个布尔值:将比较结果包裹在boolean()中,确保返回单个布尔值
<xsl:template match="table[boolean(preceding-sibling::div[@class='sectionclass'][1]/text()[1]='Physical Properties:')]/tbody">
  1. 标准化文本内容:用normalize-space()处理文本,避免空格、换行等干扰,同时确保比较逻辑的一致性
<xsl:template match="table[normalize-space(preceding-sibling::div[@class='sectionclass'][1]/text()[1])='Physical Properties:']/tbody">

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 18:45:04