You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by "Hagan, Jeffrey G" <je...@baesystems.com> on 2002/08/19 19:26:02 UTC

FW: Using a Xalan Node, bridged from Xerces, as an input to an XS L Transformation

Hello,

 

I am using Xalan 1.3/Xerces 1.6 and am trying to do something like the
following:

 

1) Build a Xerces DOM_Document in the Xerces suggested manner (as
demonstrated in the Xerces CreateDOMDocument sample)

 

2) Convert the entire Xerces DOM_Document over to Xalan with the
XercesDocumentBridge using code like (note that I am creating the deep copy
because I have found that XML serialization with the FormatterToXML class is
much faster if this is done):

 

                XercesDocumentBridge        *theBridge = NULL;

                XercesDOMSupport             domSupport;

                XercesParserLiaison          parserLiaison(domSupport);

 

                XalanDocument* const         newXalanDoc =
parserLiaison.createDocument(xercesDoc);

                XercesDocumentBridge *theLocalBridge =
parserLiaison.mapDocument(newXalanDoc);

 

                // Create a Deep Copy

                theBridge = theLocalBridge->cloneNode(true);

 

3) Use the XalanDocument as an input to an XSL Transformation with a call
like the following

 

            XalanTransformer theXalanTransformer;

 

            int result = theXalanTransformer.transform(theBridge,
"/path/to/my/stylesheet.xsl", "/path/to/my/outputFile"); 

 

            if ( result != 0 ) {

                cerr << "SimpleTransform Error: \n" <<
theXalanTransformer.getLastError()

                     << endl

                     << endl;

            }

 

 

Basically, I am trying to use the XercesDocumentBridge to initialize the
first XSLTInputSource argument to the XalanTransformer method:

int

transform(       

                const XSLTInputSource&          theInputSource,

                const XSLTInputSource&          theStylesheetSource,

                const XSLTResultTarget&         theResultTarget);

 

but I always get the following error:

 

Fatal Error at (file , line 0, column 0): An exception occured!
Type:RuntimeException, Message:The primary document entity could not be
opened. Id={null}

 

 

I can only get this to work by a) using the DOM_Document itself as the input
to the transformation with XercesDOMWrapperParsedSource or b) serializing
the XercesDocumentBridge to an XML istream and using that as the input to
the transformation.

 

                                           

Here are the reasons that I wish to do things in the manner described above:

a)       Why use Xerces to build the document, rather than
XalanDocumentBuilder?

a.       I would like to use Xerces because the construction of the DOM
Document is rather complex and we need the flexibility offered by the DOM
API to construct nodes in a robust/flexible manner.  We also want to make
the DOM Node navigation methods (getChildNodes, getElementsByTagName, etc.)
available to applications that will use our constructed document.

b)      Why not use the Xerces DOM_Document as the input to the
transformation with XercesDOMWrapperParsedSource, rather than bridging the
Xerces DOM_Document over to Xalan and then performing the transformation?

a.       I would prefer to use XalanNodes, rather than DOM_Nodes, because we
want our application users to be able to navigate through Nodes within our
constructed document by (a transformation is just one thing we want our
users to be able to do with the document)

 
i.      DOM Node navigation methods (offered in both Xalan DOM and Xerces
DOM)

                                                                         ii.
Xpath node traversal methods (XPathEvaluator::selectSingleNode,
XPathEvaluator::selectNodeList), which are only offered in the Xalan DOM.  I
don't want to have to bridge the selection results back to Xerces DOM_Nodes.

b.      We also want our application users to be able to transform Nodes as
many times as they like from any Node in the document.  This means that we
want to avoid performing Xerces DOM_Node parsing as much as possible.  If we
could perform this all at once, this would be optimal.

 

Any help would be greatly appreciated.  

 

Thank you,

 

 

Jeff Hagan