Goffena, Robert wrote:
I’ve converted a xerces dom document to a XercesDOMWrapperParsedSource
and call XalanTransformer to transform the xml.
The XalanTransformer succeeds in creating the output, however the
transformation behaves as if it could not locate any of the input xml’s
attributes.
Code to make this happen looks like the following:
DOMDocument pDomDocument = NULL;
populateDomDocument( pDomDocument ); // a method I have to populate the
dom document with elements/attributes.
Please make sure you're creating a namespace-aware DOM. You must use
DOMDocument::createElementNS(), DOMElement::setAttributeNS() and
DOMDocument::createAttributeNS(). Also, if you expect xsl:copy and
xsl:copy-of to work correctly with namespace nodes, you will need to
make sure you add the appropriate attributes in the proper namespace for
each namespace declaration.
This can be pretty tricky, so you might want to take a look at the
Namespaces recommendation for more details about the proper namespaces
for the attributes that declare the namespaces.
XercesParserLiaison theParserLiaison;
XercesDOMSupport theDOMSupport( theParserLiaison );
XercesDOMWrapperParsedSource inputData( pDomDocument, theParserLiaison,
theDOMSupport );
XSLTInputSource stylesheet( “c:/test/test.xsl” );
XSLTResultTarget result( “c:/test/output.out” );
XalanTransformer* xtran = new XalanTransformer();
xtran->transform( inputdata, stylesheet, result );
Additional details:
I have dumped the pDomDocument to the c:/test directory and added a
processing statement:
<?xml-stylesheet type=”text/xsl” href=”test.xsl”>
When I double click on this pDomDocument dump file, it opens in Internet
Explorer, and IE displays the file as having been transformed correctly
(attributes were selected).
And if you let Xalan-C build its own source tree from the markup, I'm
sure it would work as well. You can test this by using the Xalan executable:
Xalan -a dump.xml
The root tag/element of pDomDocument has a namespace.
There is a big difference between markup and the resulting DOM tree,
particularly with regard to namespaces.
Dave