You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by au...@apache.org on 2001/04/19 20:44:41 UTC
cvs commit: xml-xalan/c/samples/CompileStylesheet CompileStylesheet.cpp
auriemma 01/04/19 11:44:40
Modified: c/samples/CompileStylesheet CompileStylesheet.cpp
Log:
Updated to use the XalanTransformer class.
Revision Changes Path
1.17 +51 -133 xml-xalan/c/samples/CompileStylesheet/CompileStylesheet.cpp
Index: CompileStylesheet.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/samples/CompileStylesheet/CompileStylesheet.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- CompileStylesheet.cpp 2001/01/08 20:26:22 1.16
+++ CompileStylesheet.cpp 2001/04/19 18:44:38 1.17
@@ -23,31 +23,10 @@
-#include <PlatformSupport/DOMStringHelper.hpp>
+#include <XalanTransformer/XalanTransformer.hpp>
-#include <XPath/XObjectFactoryDefault.hpp>
-#include <XPath/XPathFactoryDefault.hpp>
-
-
-
-#include <XSLT/StylesheetConstructionContextDefault.hpp>
-#include <XSLT/StylesheetExecutionContextDefault.hpp>
-#include <XSLT/StylesheetRoot.hpp>
-#include <XSLT/XSLTEngineImpl.hpp>
-#include <XSLT/XSLTInit.hpp>
-#include <XSLT/XSLTInputSource.hpp>
-#include <XSLT/XSLTProcessorEnvSupportDefault.hpp>
-#include <XSLT/XSLTResultTarget.hpp>
-
-
-
-#include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
-#include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
-
-
-
int
main(
int argc,
@@ -60,6 +39,8 @@
using std::ostrstream;
#endif
+ int theResult = 0;
+
if (argc != 1)
{
cerr << "Usage: CompileStylesheet"
@@ -68,121 +49,58 @@
}
else
{
- try
- {
- // Call the static initializer for Xerces...
- XMLPlatformUtils::Initialize();
+ // Call the static initializer for Xerces.
+ XMLPlatformUtils::Initialize();
- {
- // Initialize the Xalan XSLT subsystem...
- XSLTInit theInit;
+ // Initialize Xalan.
+ XalanTransformer::initialize();
- // Create some support objects that are necessary for running the processor...
- XalanSourceTreeDOMSupport theDOMSupport;
- XalanSourceTreeParserLiaison theParserLiaison(theDOMSupport);
-
- // Hook the two together...
- theDOMSupport.setParserLiaison(&theParserLiaison);
-
- // Create some more support objects.
- 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 separate factory support objects so the stylesheet's
- // factory-created XPath instances are independent from the
- // processor's.
- XPathFactoryDefault theStylesheetXPathFactory;
-
- // Create a stylesheet construction context, using the
- // stylesheet's factory support objects.
- StylesheetConstructionContextDefault theConstructionContext(
- theProcessor,
- theXSLTProcessorEnvSupport,
- theStylesheetXPathFactory);
-
- // The execution context uses the same factory support objects as
- // the processor, since those objects have the same lifetime as
- // other objects created as a result of the execution.
- StylesheetExecutionContextDefault theExecutionContext(
- theProcessor,
- theXSLTProcessorEnvSupport,
- theDOMSupport,
- theXObjectFactory);
-
- // Our input file. The assumption is that the executable will be run
- // from same directory as the input files.
- const XalanDOMString theXSLFileName("foo.xsl");
-
- // Our stylesheet input source...
- XSLTInputSource theStylesheetSource(c_wstr(theXSLFileName));
-
- // Ask the processor to create a StylesheetRoot for the specified
- // input XSL. This is the compiled stylesheet. We don't have to
- // delete it, since it is owned by the StylesheetConstructionContext
- // instance.
- StylesheetRoot* const theStylesheetRoot =
- theProcessor.processStylesheet(
- theStylesheetSource,
- theConstructionContext);
- assert(theStylesheetRoot != 0);
-
- for (unsigned int i = 0; i < 10; i++)
- {
- theExecutionContext.setStylesheetRoot(theStylesheetRoot);
-
- // Buffers passed in to ostrstream.
- char inBuffer[10];
- char outBuffer[10];
-
- // Generate the input and output file names.
- ostrstream theFormatterIn(inBuffer, sizeof(inBuffer));
- ostrstream theFormatterOut(outBuffer, sizeof(outBuffer));
-
- theFormatterIn << "foo" << i + 1 << ".xml" << '\0';
- theFormatterOut << "foo" << i + 1 << ".out" << '\0';
-
- //Generate the XML input and output objects.
- XSLTInputSource theInputSource(theFormatterIn.str());
- XSLTResultTarget theResultTarget(XalanDOMString(theFormatterOut.str()));
-
- // Do the tranformation...
- theProcessor.process(
- theInputSource,
- theResultTarget,
- theExecutionContext);
-
- // Reset the processor and the execution context
- // so we can perform the next transformation.
- // Reset the parser liaison to clear out the
- // source document we just transformed.
- theProcessor.reset();
- theExecutionContext.reset();
- theParserLiaison.reset();
- }
- }
+ // Create a XalanTransformer.
+ XalanTransformer theXalanTransformer;
- // Call the static terminator for Xerces...
- XMLPlatformUtils::Terminate();
- }
- catch(...)
- {
- cerr << "Exception caught!!!"
- << endl
- << endl;
+ // Our input files...The assumption is that the executable will be run
+ // from same directory as the input files.
+ const char* theXSLFileName = "foo.xsl";
+
+ // Compile the stylesheet.
+ const XalanCompiledStylesheet* const theCompiledStylesheet =
+ theXalanTransformer.compileStylesheet(theXSLFileName);
+
+ assert(theCompiledStylesheet != 0);
+
+ for (unsigned int i = 0; i < 10; i++)
+ {
+ // Buffers passed in to ostrstream.
+ char inBuffer[10];
+ char outBuffer[10];
+
+ // Generate the input and output file names.
+ ostrstream theFormatterIn(inBuffer, sizeof(inBuffer));
+ ostrstream theFormatterOut(outBuffer, sizeof(outBuffer));
+
+ theFormatterIn << "foo" << i + 1 << ".xml" << '\0';
+ theFormatterOut << "foo" << i + 1 << ".out" << '\0';
+
+ char* theXMLFileName = theFormatterIn.str();
+ char* theOutputFileName = theFormatterOut.str();
+
+ // Do the transform.
+ theResult = theXalanTransformer.transform(theXMLFileName, theCompiledStylesheet, theOutputFileName);
+
+ if(theResult != 0)
+ {
+ cerr << "CompileStylesheet Error: \n" << theXalanTransformer.getLastError()
+ << endl
+ << endl;
+ }
}
+
+ // Terminate Xalan.
+ XalanTransformer::terminate();
+
+ // Call the static terminator for Xerces.
+ XMLPlatformUtils::Terminate();
}
- return 0;
+ return theResult;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org