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

咨询Saxon EE 9.9中XSLT 3.0调用带Update功能的XQuery的可行性

在Saxon EE 9.9中通过XSLT调用带Update功能的XQuery

Saxon EE 9.9完全支持通过saxon:compile-query/saxon:query扩展函数,在XSLT 3.0脚本中运行带有Update功能的XQuery代码,包括copy modify return表达式和XQuery Update Facility(XQUF)定义的更新函数。

关键细节说明

  • 支持范围:Saxon EE从9.3版本开始就实现了XQuery Update Facility 1.0规范,9.9版本对该规范的支持是完整的,copy modify return这类核心更新语法,以及fn:insert-node、fn:delete-node、fn:replace-node等标准更新函数都能正常执行。
  • 启用更新模式:调用时必须显式指定更新模式,通过saxon:compile-query的update参数设为yes,或在saxon:query元素中添加update="yes"属性,否则更新操作会报错。
  • 上下文共享:XQuery更新操作针对的是当前内存中的节点树,更新后的节点会直接反映到XSLT的后续处理上下文中,无需额外传递。
  • 原子性保障:Saxon会自动确保单个XQuery更新语句内的所有操作具备原子性,要么全部执行成功,要么全部回滚。

示例代码

以下是XSLT中调用带copy modify return的XQuery的简单示例:

<xsl:stylesheet version="3.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:saxon="http://saxon.sf.net/">

  <xsl:template match="/">
    <!-- 执行XQuery更新操作 -->
    <xsl:variable name="updated-doc">
      <saxon:query update="yes">
        copy $target := .
        modify (
          delete node $target//deprecated-node,
          insert node &lt;new-node&gt;替换内容&lt;/new-node&gt; as last into $target//container
        )
        return $target
      </saxon:query>
    </xsl:variable>

    <!-- 输出更新后的文档 -->
    <xsl:copy-of select="$updated-doc"/>
  </xsl:template>

</xsl:stylesheet>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 15:13:20