咨询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 <new-node>替换内容</new-node> as last into $target//container ) return $target </saxon:query> </xsl:variable> <!-- 输出更新后的文档 --> <xsl:copy-of select="$updated-doc"/> </xsl:template> </xsl:stylesheet>
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

