Hi Dave,

Thanks for your reply.

Please see the function below, which transforms a xerces document successfully. 
Please provide your comments whether its okay or not.
I am having two problems though:
1. It crashes when I uncomment XMLPlatformUtils::Terminate(); at the end of the 
function.
2. I see there is one extra blank line added to every line in the output file 
(trans.xml), which I need to avoid. 

Any suggestions on these ?

Regards,
Indrajit


void transformDOM()
{
        XALAN_USING_XALAN(XalanDOMString)
     XALAN_USING_XALAN(XercesDOMSupport)
     XALAN_USING_XALAN(XercesParserLiaison)
     XALAN_USING_XALAN(ElementPrefixResolverProxy)
     XALAN_USING_XALAN(XercesDocumentWrapper)

         XALAN_USING_XERCES(XMLPlatformUtils)
        XALAN_USING_XALAN(XalanTransformer)

        XMLPlatformUtils::Initialize();


        DOMImplementation* impl =  
DOMImplementationRegistry::getDOMImplementation(X("Core"));
        xercesc::DOMBuilder* builder = 
impl->createDOMBuilder(xercesc::DOMImplementationLS::MODE_SYNCHRONOUS,
                                                                                
        0);
        

        //builder->setFeature(xercesc::XMLUni::fgDOMValidation, true);
        builder->setFeature(xercesc::XMLUni::fgDOMNamespaces, true);
        builder->setFeature(xercesc::XMLUni::fgXercesSchema   , true);
        

        xercesc::DOMDocument* pDoc = builder->parseURI(X("c:\\A.xml"));

        XercesDOMSupport      theDOMSupport;
    XercesParserLiaison   theParserLiaison(theDOMSupport);
        theParserLiaison.setUseValidation(true);
        theParserLiaison.setIncludeIgnorableWhitespace(false);


         xalanc::XercesDOMWrapperParsedSource theWrapper(pDoc, 
theParserLiaison, theDOMSupport);


        // Initialize Xalan.
                XalanTransformer::initialize();

                {
                        // Create a XalanTransformer.
                        XalanTransformer theXalanTransformer;

                        // Do the transform.
        
                        const string    xslFile("c:\\my.xsl");
                        ifstream xsl(xslFile.c_str());
                        const string    outfile("c:\\trans.xml");
                        ofstream tgt(outfile.c_str());

                        const xalanc::XalanParsedSource*        theParsedSource 
= 0;

                        int ret = theXalanTransformer.transform(theWrapper, 
xsl, tgt);
                        
    
                        if(ret != 0)
                        {
                                                                CString err = 
theXalanTransformer.getLastError();
                                AfxMessageBox(err);
                        }
                        else
                                AfxMessageBox("Transformed successfully !!");
                }

                // Terminate Xalan...
                XalanTransformer::terminate();

//              XMLPlatformUtils::Terminate();
}  


On Thu, 22 Feb 2007 David Bertoni wrote :
>Indrajit Bhattacharya wrote:
>>Hi,
>>
>>I have yet another query and need help from you. This is regarding XSLT.
>>
>>I have application data as Xercesc DOM nodes. Can I do XSLT transform on the 
>>root node ? In the sample XalanTransform, it takes one input XML file, one 
>>XSL file and produces an output file.
>>In my case, I will have xerces DOM root node pointer and XSL file. Can I run 
>>transform function of the XalanTransformer object with my data ?
>
>Wrapping the Xerces-C DOM for an XSLT transformation is exactly the same as 
>wrapping it for use with the XPathEvaluator.
>
>Dave

Reply via email to