You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Da...@lotus.com on 2000/06/29 00:09:51 UTC

RE: Writing resulting HTML into a buffer instead of to a file - N ewbi e

Writing to a buffer is very straightforward.

XSLTResultTarget takes a pointer to a std::ostream as a constructor
parameter.  Just create a strstream or stringstream (depending on which
your compiler's library supports), and use that to construct the
XSLTResultTarget. Here's the Xalan sample SimpleTransform.cpp modified to
write to a stringstream:

#include <iostream>
#include <fstream>
#include <sstream>

#include <util/PlatformUtils.hpp>

#include <PlatformSupport/DOMStringHelper.hpp>

#include <DOMSupport/DOMSupportDefault.hpp>

#include <XPath/XObjectFactoryDefault.hpp>
#include <XPath/XPathSupportDefault.hpp>
#include <XPath/XPathFactoryDefault.hpp>

#include <XSLT/StylesheetConstructionContextDefault.hpp>
#include <XSLT/StylesheetExecutionContextDefault.hpp>
#include <XSLT/XSLTEngineImpl.hpp>
#include <XSLT/XSLTInputSource.hpp>
#include <XSLT/XSLTProcessorEnvSupportDefault.hpp>
#include <XSLT/XSLTResultTarget.hpp>

#include <XercesParserLiaison/XercesParserLiaison.hpp>

#include <XercesPlatformSupport/TextFileOutputStream.hpp>
#include <XercesPlatformSupport/XercesDOMPrintWriter.hpp>

int
main(
               int                 argc,
               const char*         /* argv */[])
{
#if !defined(XALAN_NO_NAMESPACES)
     using std::cerr;
     using std::endl;
     using std::ofstream;
     using std::stringstream;
#endif

     if (argc != 1)
     {
          cerr << "Usage: SimpleTransform"
                << endl
                << endl;
     }
     else
     {
          try
          {
               // Call the static initializers...
               XMLPlatformUtils::Initialize();
               XSLTEngineImpl::Initialize();

               // Create the support objects that are necessary for running
the processor...
               DOMSupportDefault                   theDOMSupport;
               XercesParserLiaison
theParserLiaison(theDOMSupport);
               XPathSupportDefault
theXPathSupport(theDOMSupport);
               XSLTProcessorEnvSupportDefault
theXSLTProcessorEnvSupport;
               XObjectFactoryDefault
theXObjectFactory(theXSLTProcessorEnvSupport, theXPathSupport);
               XPathFactoryDefault                 theXPathFactory;

               // Create a processor...
               XSLTEngineImpl theProcessor(
                         theParserLiaison,
                         theXPathSupport,
                         theXSLTProcessorEnvSupport,
                         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,
                              theXObjectFactory,
                              theXPathFactory);

               StylesheetExecutionContextDefault        theExecutionContext
(
                              theProcessor,
                              theXSLTProcessorEnvSupport,
                              theXPathSupport,
                              theXObjectFactory);

               // Our input files...The assumption is that the executable
will be run
               // from same directory as the input files.
               const XalanDOMString           theXMLFileName("foo.xml");
               const XalanDOMString           theXSLFileName("foo.xsl");

               // Our input sources...
               XSLTInputSource
theInputSource(c_wstr(theXMLFileName));
               XSLTInputSource
theStylesheetSource(c_wstr(theXSLFileName));

               // Our output target...
               stringstream              theStream;
               XSLTResultTarget          theResultTarget(&theStream);

               theProcessor.process(
                              theInputSource,
                              theStylesheetSource,
                              theResultTarget,
                              theConstructionContext,
                              theExecutionContext);

               // theStream now contains the result of the transform.
Let's write it to cerr...
               cerr << theStream.str();
          }
          catch(...)
          {
               cerr << "Exception caught!!!"
                     << endl
                     << endl;
          }
     }

     return 0;
}

Dave



                                                                                                                                   
                    "Phillips,                                                                                                     
                    Andrew"                  To:     "'xalan-dev@xml.apache.org'" <xa...@xml.apache.org>                       
                    <Andrew_Phillips@        cc:     (bcc: David N Bertoni/CAM/Lotus)                                              
                    Mitel.COM>               Subject:     RE: Writing resulting HTML into a buffer instead of to a file - N ewbi e 
                                                                                                                                   
                    06/28/2000 05:21                                                                                               
                    PM                                                                                                             
                    Please respond to                                                                                              
                    xalan-dev                                                                                                      
                                                                                                                                   
                                                                                                                                   



Sorry,

           I'm using the C++ version of Xalan.

Thanks,
Andrew

-----Original Message-----
From: David_N_Bertoni@lotus.com [mailto:David_N_Bertoni@lotus.com]
Sent: Wednesday, June 28, 2000 5:15 PM
To: xalan-dev@xml.apache.org
Subject: Re: Writing resulting HTML into a buffer instead of to a file -
Newbi e



If you tell us whether you're using the Java version or the C++ version of
Xalan, someone can answer the question.

Dave




                    "Phillips,

                    Andrew"                  To:
"'xalan-dev@xml.apache.org'" <xa...@xml.apache.org>

                    <Andrew_Phillips@        cc:     (bcc: David N
Bertoni/CAM/Lotus)
                    Mitel.COM>               Subject:     Writing resulting
HTML into a buffer instead of to a file - Newbi e

                    06/28/2000 05:07

                    PM

                    Please respond to

                    xalan-dev






Hey,

           I am trying to create HTML by combining XML in a buffer with a
XSL and have the results stored in a buffer.  Its running to this point but
the resulting HTML is being stored in a file.  The problem I am having is I
believe that this functionality isn't supported yet.  Has anyone attempted
this, if so could you please forward me some tips or some sample code.

Thanks in advance

Andrew Phillips