Oracle XSLProcessor returns an XMLDocumentFragment and I need anXMLDocument (or XMLType) (or even St

S

Stryder

I'm trying to do something that should be simple. In Oracle 11g, I'm
trying to write a Java stored procedure that applies an XSLT
stylesheet to an XML document and returns it as type XMLType.

Here's a snippet that shows the question...

public static XMLType bwdtransform(oracle.sql.CLOB documentText)
throws Exception {
// ==============================
// This works - oracle.xml.parser.v2.DOMParser parses the incoming
CLOB into an
// oracle.xml.parser.v2.XMLDocument
// ==============================
parser.parse(documentText.getCharacterStream());
XMLDocument xmlDocument = (XMLDocument) parser.getDocument();

// ==============================
// This works - applies adopterXSLT, which is a
oracle.xml.parser.v2.XSLStylesheet,
// to the XMLDocument, returning an XMLDocumentFragment. It'd
solve the problem
// if this could return an XMLDocument, but it doesn't
// ==============================
XMLDocumentFragment xmlDocumentFragment = processor.processXSL
(adopterXSLT, xmlDocument);

// ==============================
// This DOES NOT work. XMLType requires an XMLDocument, not an
XMLDocumentFragment
// as its second parameter. I can find no way to translate an
XMLDocumentFragment into
// an XMLDocument, an XMLType, or even serialize it to a string.
// ==============================
return new XMLType(conn, xmlDocumentFragment);
}

Any help in returning the result of applying the stylesheet as an
XMLType would be very
very greatly appreciated.

Thanks.

Ralph
 
M

Martin Honnen

Stryder said:
I'm trying to do something that should be simple. In Oracle 11g, I'm
trying to write a Java stored procedure that applies an XSLT
stylesheet to an XML document and returns it as type XMLType.

Here's a snippet that shows the question...

public static XMLType bwdtransform(oracle.sql.CLOB documentText)
throws Exception {
// ==============================
// This works - oracle.xml.parser.v2.DOMParser parses the incoming
CLOB into an
// oracle.xml.parser.v2.XMLDocument
// ==============================
parser.parse(documentText.getCharacterStream());
XMLDocument xmlDocument = (XMLDocument) parser.getDocument();

// ==============================
// This works - applies adopterXSLT, which is a
oracle.xml.parser.v2.XSLStylesheet,
// to the XMLDocument, returning an XMLDocumentFragment. It'd
solve the problem
// if this could return an XMLDocument, but it doesn't
// ==============================
XMLDocumentFragment xmlDocumentFragment = processor.processXSL
(adopterXSLT, xmlDocument);

Does
XMLDocument doc = (XMLDocument)xmlDocumentFragment.getOwnerDocument();
give you an object? Or is that null? If it is not null and is an empty
document then you could simply do
doc.appendChild(xmlDocumentFragment);
assuming your XSLT stylesheet does indeed create a document with a
single root element.
Or create a new document
XMLDocument doc = new XMLDocument();
and do
doc.appendChild(doc.adoptNode(xmlDocumentFragment));
 
S

Stryder

Does
   XMLDocument doc = (XMLDocument)xmlDocumentFragment.getOwnerDocument();
give you an object? Or is that null? If it is not null and is an empty
document then you could simply do
  doc.appendChild(xmlDocumentFragment);
assuming your XSLT stylesheet does indeed create a document with a
single root element.
Or create a new document
   XMLDocument doc = new XMLDocument();
and do
   doc.appendChild(doc.adoptNode(xmlDocumentFragment));

The second option did it. Thank you thank you thank you.
 

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top