With all the hints of the last couple of days, I put the
parts together as follows (critique welcome):

/*
 * Simple transformation with Xerces DOM input
 * Mostly taken from the TraceListen sample
 */

#include <strstream>
#include <iostream>
#include <fstream>
#include <util/PlatformUtils.hpp>
#include <XercesParserLiaison/XercesDOMSupport.hpp>
#include <XercesParserLiaison/XercesParserLiaison.hpp>
#include <XPath/XObjectFactoryDefault.hpp>
#include <XPath/XPathFactoryDefault.hpp>
#include <XPath/XPathProcessorImpl.hpp>
#include <XSLT/XSLTEngineImpl.hpp>
#include <XSLT/XSLTInit.hpp>
#include <XSLT/XSLTInputSource.hpp>
#include <XSLT/XSLTResultTarget.hpp>
#include <XSLT/StylesheetConstructionContextDefault.hpp>
#include <XSLT/StylesheetExecutionContextDefault.hpp>
#include <XSLT/XSLTProcessorEnvSupportDefault.hpp>


int main(int argc, char* argv[])
{
    XMLPlatformUtils::Initialize();

    /* Create simple Xerces DOM */
    DOM_DOMImplementation impl;
    DOM_Document domDoc = impl.createDocument( 0, "Root",
DOM_DocumentType());
    DOM_Element rootElem = domDoc.getDocumentElement();
    DOM_Element  firstElement = domDoc.createElement("FirstElement");
    firstElement.setAttribute( "firstAttributeOfFirstElement",
"some-value" );
    rootElem.appendChild(firstElement);
    DOM_Text firstText = domDoc.createTextNode("This is a text node.");
    firstElement.appendChild(firstText);

    /* Transform DOM */
    try
    {
        XSLTInit                        theInit;
        XercesDOMSupport                theDOMSupport;
        XercesParserLiaison             theParserLiaison(theDOMSupport);

        XSLTProcessorEnvSupportDefault  theXSLTProcessorEnvSupport;
        XObjectFactoryDefault           theXObjectFactory;
        XPathFactoryDefault             theXPathFactory;

        // Create a processor...
        XSLTEngineImpl  theProcessor( theParserLiaison,
            theXSLTProcessorEnvSupport, theDOMSupport, theXObjectFactory,
            theXPathFactory);

        // Connect the processor to the support object...
        theXSLTProcessorEnvSupport.setProcessor(&theProcessor);

        // Create a stylesheet construction context, and a stylesheet
        // execution context...
        StylesheetConstructionContextDefault theConstructionContext(
            theProcessor, theXSLTProcessorEnvSupport, theXPathFactory);
        StylesheetExecutionContextDefault theExecutionContext( theProcessor,
            theXSLTProcessorEnvSupport, theDOMSupport, theXObjectFactory);

        XalanDocument* xalanDoc = theParserLiaison.createDocument(domDoc);
        const XSLTInputSource domIn(xalanDoc);

        const XSLTInputSource theXsl("copy.xsl");
        const XalanDOMString  target("out.xml");
        XSLTResultTarget      theResultTarget(target);

        theProcessor.process (  domIn, theXsl, theResultTarget,
            theConstructionContext, theExecutionContext );
    }
    catch(...)
    {
        std::cerr << "Some error happened!" << std::endl;
    }
    XMLPlatformUtils::Terminate();
    return 1;
}

-----Original Message-----
From: Bryan Mulvihill [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 04, 2001 11:36 PM
To: [EMAIL PROTECTED]
Subject: Re: DOM Input woes



The usage pattern doc was what I was using.  Unfortuneatly it stops after
the XSLTInputSource.  The TraceListen sample doesn't use a Xerces DOM so
mixing the two has given mysterious crashes and I'm not sure as to what does
what.  If anybody has working Xerces DOM conversion, then I would like to
see it.


>
> You can still transform a Xerces DOM instance dynamically, you just can't
> use a XalanTransformer instance to do it.
>
> If you're using the internal APIs, then nothing changes.  The TraceListen
> sample still uses the internal APIs, so you can look there for information
> on how to use those APIs.  You can also see this usage pattern which is in
> the doc for more information on how to substitute the Xerces DOM for our
> source tree:
>
>    http://xml.apache.org/xalan-c/usagepatterns.html#dom
>
> Dave
>
>
>
>
>                       "Bryan
>                       Mulvihill"               To:
<[EMAIL PROTECTED]>
>                       <bryan@amconrese         cc:      (bcc: David N
Bertoni/CAM/Lotus)
>                       arch.net>                Subject: DOM Input woes
>
>                       09/04/2001 01:30
>                       PM
>                       Please respond
>                       to xalan-dev
>
>
>
>
>
> I am trying to transform a xerces DOM that is created dynamically, but
> after going through the archieves, it appears that this cannot be
> accomplished in ver.1.2.
>
> Is there a way to serializer my DOM and pass that to xalan?  If so, can
you
> give a small code sample?
>
> Can a Xalan DOM be generated dynamically and then transformed? If so, can
> you give a small code sample?
>
> Any help would be much appreciated.
>
> Bryan Mulvihill
> Software Developer
> AMCon Research Inc., Ottawa, Ontario, Canada
> http://www.amconresearch.com
>
>


Reply via email to