Project

Profile

Help

Java Extension Function returning Node

Added by Anonymous almost 14 years ago

Legacy ID: #8510542 Legacy Poster: https://www.google.com/accounts ()

I have a Java Extension function that returns a org.w3c.dom.Node and within the java function, I org.apache.xerces.dom.DocumentImpl() to generate a document containing several Nodes. When the Node is returned to XSLT, Saxon seems to be losing all XML tags, and only values are serialized to the output. I am using Saxon EE 9.2


Replies (3)

Please register to reply

RE: Java Extension Function returning Node - Added by Anonymous almost 14 years ago

Legacy ID: #8511341 Legacy Poster: Michael Kay (mhkay)

You'll have to be more specific: show exactly what your extension function is doing, and exactly what the XSLT code is doing with the result. Then I'll be able to tell whether you are doing something wrong or whether there's a Saxon problem. Ideally provide enough information so that someone else can reproduce the problem.

RE: Java Extension Function returning Node - Added by Anonymous almost 14 years ago

Legacy ID: #8512379 Legacy Poster: https://www.google.com/accounts ()

Here's the Java Extension method that returns a Node. [code] public Node getHeader() throws XSLTExtensionException { try { Document doc = new org.apache.xerces.dom.DocumentImpl(); Element header = doc.createElement("Header"); String fromID = "FromID"; String toID = "ToID"; Node from = doc.createElement("From"); Element identity = doc.createElement("Identity"); Text t = doc.createTextNode( fromID ); identity.appendChild(t); from.appendChild(identity); header.appendChild(from); Node to = doc.createElement("To"); Element identity2 = doc.createElement("Identity"); Text t2 = doc.createTextNode( toID ); identity2.appendChild(t2); to.appendChild(identity2); header.appendChild(to); return header; } catch (Throwable t) { throw new XSLTExtensionException("getHeader " + t.getMessage()); } } [/code] Here's a simple XSLT that invokes the extension and serializes the node. [code] ]> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:saxon='http://saxon.sf.net/' xmlns:util='java:com.test.xsltextension.Utilities' extension-element-prefixes='util' exclude-result-prefixes='util' version='1.0'> <xsl:output method='xml' version='1.0' encoding='UTF-8' omit-xml-declaration='no' doctype-system='&DOCTYPE-SYSTEM;' indent='yes' /> <xsl:variable name="util" select="util:new()" /> <xsl:template match="/"> <xsl:call-template name='Envelope'/> </xsl:template> <xsl:template name='Envelope'> <xsl:call-template name="DocumentHeader"/> </xsl:template> <xsl:template name="DocumentHeader"> <xsl:value-of select="util:getHeader($util)"/> </xsl:template> </xsl:stylesheet>[/code] The output does not include XML tags for the node returned by the extension. [code][b]FromIDToID[/b][/code]

RE: Java Extension Function returning Node - Added by Anonymous almost 14 years ago

Legacy ID: #8512444 Legacy Poster: Michael Kay (mhkay)

The xsl:value-of instruction always produces a single text node. Try xsl:copy-of.

    (1-3/3)

    Please register to reply