Saxon-HE 集成扩展功能 [英] Saxon-HE Integrated Extension Functions

查看:43
本文介绍了Saxon-HE 集成扩展功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初应该通过声明我们的代码使用嵌入式撒克逊扩展函数 - saxon:parse($xml) 来发布我的问题,该函数返回 xml 的根元素/节点.但是,在 Saxon-HE 中,该扩展不再可用 - 因此我正在尝试编写一个集成扩展,将 xml 字符串解析为文档并返回根元素.

我正在使用 Saxon-HE 9.5.1.6 - 我正在尝试编写一个返回文档根节点的集成扩展函数.该函数接收一个 xml 字符串 - 创建一个文档,需要将根节点返回给 xslt,然后使用 xpath 查找特定元素.ExtensionFunctionCall 类/类型的 call() 方法返回 Sequence 类型 - 如何返回 NodeSequence 或 NodeType?如何从我的文档构建 NodeSequence?

我可以逐步调试并确认函数接收到正确的 xml - 将其解析为文档,但到目前为止我无法确定如何使用我的 RootElement 构建 NodeSequence.

我有其他返回 StringValue 的集成扩展函数 - 那些工作得很好,但我无法从可用的类方法中收集如何从 ExtensionFunctionCall 返回简单(数字/字母/项目)类型以外的任何内容

谢谢.

解决方案

DocumentInfo 类实现了 Sequence,所以如果你返回一个 DocumentInfo,那将满足接口.您可以使用

构造一个 DocumentInfo

context.getConfiguration().buildDocument()

如果您想使用一些外部对象模型(例如 DOM 或 JDOM2)构建您的文档,您将需要获取该外部文档的根节点并将其包装在适当类型的 Saxon DocumentWrapper 中以使其成为 DocumentInfo.

I should have originally posted my question by stating that our code was using an embedded saxon extension function - saxon:parse($xml) which returned the root element/node of the xml. However, in Saxon-HE that extension is no longer available - so I am trying to write an Integrated extension that parses an xml string into a document and returns the root element.

I am using Saxon-HE 9.5.1.6 - I am trying to write an Integrated Extension Function that returns the ROOT Node of a Document. The function receives an xml string - creates a document and needs to return the root node to the xslt for it to then use xpath to find a specific element. The call() method of the ExtensionFunctionCall class/types return a Sequence type - how do I return a NodeSequence or NodeType? How do I construct the NodeSequence from my Document?

I can step and debug and confirm the function receives the correct xml - parses this into a document, but so far I am unable to determine how to construct the NodeSequence with my RootElement.

I have other Integrated Extension Functions that return a StringValue - and those work great, but I can't glean from the class methods available how to return anything other than simple (numerica/alpha/item) types from the ExtensionFunctionCall

Thank you.

解决方案

The class DocumentInfo implements Sequence, so if you return a DocumentInfo, that will satisfy the interface. You can construct a DocumentInfo using

context.getConfiguration().buildDocument()

If you want to construct your document using some external object model such as DOM or JDOM2, you will need to take the root node of that external document and wrap it in the appropriate kind of Saxon DocumentWrapper to make it into a DocumentInfo.

这篇关于Saxon-HE 集成扩展功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆