Saxon-HE Integrated Extension Functions

泄露秘密 提交于 2021-01-28 06:54:05

问题


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.


回答1:


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.




回答2:


For anyone reading - following this I was able to get this working with Michael Kay's help - my solution is the following:

Source source = new StreamSource(new StringReader(myXMLparam));
DocumentInfo docInfo = context.getConfiguration().buildDocument(source);
return docInfo;


来源:https://stackoverflow.com/questions/25776647/saxon-he-integrated-extension-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!