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 Mark Weaver <ma...@npsl.co.uk> on 2002/10/11 08:46:32 UTC
dom->dom transformation
Sadly, I'm still having trouble with this. The code I have so far goes
like:
std::ostringstream ostr;
int intermediate = 0;
for (size_t i=0;i<m_compiledStylesheets.size();++i) {
if (i == 0) {
// get document (which is a XalanSourceTreeDocument)
theDocumentBuilder[0].reset(new XalanDefaultDocumentBuilder);
XalanDocument* theResultDoc = theDocumentBuilder[0]->getDocument();
// create source tree formatter
// this is the only dirty hack: casting the XalanDocument* to
XalanAutoPtr<FormatterToSourceTree> theSourceTreeFormatter(new
FormatterToSourceTree((XalanSourceTreeDocument*) theResultDoc));
// create the result target
XSLTResultTarget theTarget(*theSourceTreeFormatter);
ret =
transform(m_parsedXML->getDocument(),m_parsedXML->createHelper(),m_compiledS
tylesheets[i].first,theTarget,theErrorMessage);
} else if (i == m_compiledStylesheets.size()-1) {
ret =
transform(theDocumentBuilder[intermediate]->getDocument(),theDocumentBuilder
[intermediate]->createHelper(),m_compiledStylesheets[i].first,&ostr,theError
Message);
}
else {
// get document (which is a XalanSourceTreeDocument)
theDocumentBuilder[1-intermediate].reset(new
XalanDefaultDocumentBuilder);
XalanDocument* theResultDoc =
theDocumentBuilder[1-intermediate]->getDocument();
// create source tree formatter
// this is the only dirty hack: casting the XalanDocument* to
XalanAutoPtr<FormatterToSourceTree> theSourceTreeFormatter(new
FormatterToSourceTree((XalanSourceTreeDocument*) theResultDoc));
// create the result target
XSLTResultTarget theTarget(*theSourceTreeFormatter);
ret =
transform(theDocumentBuilder[intermediate]->getDocument(),theDocumentBuilder
[intermediate]->createHelper(),m_compiledStylesheets[i].first,theTarget,theE
rrorMessage);
intermediate = !intermediate;
}
if (ret != 0) break;
}
Hopefully that is relatively clear (1 stylesheet is handled by a special
case). Hopefully what I am trying to is relatively clear:
preparsed xml -> intermediate #1
intermediate #1 -> intermediate #2
intermediate #2 -> (new) intermediate #1
...
intermediate #{1,2} -> final output
I realise I am not supposed to use ostringstream for MT performance (this is
just to get it working). In the case of 2 stylesheets, this works perfectly
well, but with > than that, I get a XalanDOMExeception with
HIERARCHY_REQUEST_ERR thrown from a call somewhere along the way to
XalanSourceTreeDocument::appendChildNode.
Reworking the code to keep all of the intermediate objects (targets,
formatters) hanging around doesn't help.
Any pointers greatly appreciated,
Thanks
Mark