You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by mahesh <ma...@finessealliance.com> on 2001/02/10 09:50:21 UTC
Dom Input
Hi
I compiled xalan c in solaris successfully. I was able to execute the samples given with source code.
I tried to use Dom Input to XSLT. I compiles and run well. but the output xml file I received is not correct, I could get the problem. Could you please tell me what is wrong.
The source code is
--------------------------------------------------------------------------------
int
xsltMain(const CmdLineParams& params)
{
#if defined(XALAN_USE_ICU)
// Create an installer to install the substitue format-number() function.
FunctionICUFormatNumber::FunctionICUFormatNumberInstaller theInstaller;
// Create a factory for creating XalanNumberFormat instances using
// the ICU as implementation...
ICUXalanNumberFormatFactory theXalanNumberFormatFactory;
// Install the ICU-based factory...
StylesheetExecutionContextDefault::installXalanNumberFormatFactory(&theXalanNumberFormatFactory);
#endif
// Use the Xerces DOM parser to create a DOM_Document.
DOMParser theParser;
theParser.parse("sample1.xml");
const DOM_Document theDOM = theParser.getDocument();
// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
DOMSupportDefault theDOMSupport;
XercesParserLiaison xmlParserLiaison(theDOMSupport);
XalanDocument* theDoc = xmlParserLiaison.createDocument(theDOM);
const XalanDOMString mimeEncoding(XALAN_STATIC_UCODE_STRING("UTF-8"));
const XalanDOMString encoding(XALAN_STATIC_UCODE_STRING("UTF-8"));
/**
* The default diagnostic writer...
*/
XalanStdOutputStream theStdErr(cerr);
XalanOutputStreamPrintWriter diagnosticsWriter(theStdErr);
XPathSupportDefault theXPathSupport(theDOMSupport);
XSLTProcessorEnvSupportDefault theXSLProcessorSupport;
#if defined(XALAN_USE_BLOCK_XOBJECT_FACTORY)
XObjectFactoryArena theBlockXObjectFactory;
XObjectFactoryDefault theXObjectFactoryDefault;
XObjectFactory& theXObjectFactory =
selectXObjectFactory(
theXObjectFactoryDefault,
theBlockXObjectFactory,
params.useBlockXObjectFactory);
#else
XObjectFactoryDefault theXObjectFactory;
#endif
XPathFactoryDefault theXPathFactory;
const XalanAutoPtr<TraceListener> theTraceListener(
createTraceListener(
params,
diagnosticsWriter));
XSLTEngineImpl processor(
xmlParserLiaison,
theXPathSupport,
theXSLProcessorSupport,
theDOMSupport,
theXObjectFactory,
theXPathFactory);
theXSLProcessorSupport.setProcessor(&processor);
if (theTraceListener.get() != 0)
{
processor.setTraceSelects(params.traceSelectionEvent);
processor.addTraceListener(theTraceListener.get());
}
// Use a separate factory instance for the stylesheet. This is really only necessary
// if you want to use the stylesheet with another processor, or you want to use
// it multiple times.
XPathFactoryDefault theStylesheetXPathFactory;
StylesheetConstructionContextDefault theConstructionContext(processor,
theXSLProcessorSupport,
theStylesheetXPathFactory);
/*
* Set specified processor flags
*/
processor.setQuietConflictWarnings(params.setQuietConflictWarnings);
if (params.paramsMap.size())
{
String2StringMapType::const_iterator it = params.paramsMap.begin();
for ( ; it != params.paramsMap.end(); ++it)
{
processor.setStylesheetParam(
c_str((*it).first),
c_str((*it).second));
}
}
/*
* Set specified parser flags
*/
if (params.indentAmount != 0)
{
xmlParserLiaison.setIndent(params.indentAmount);
}
xmlParserLiaison.setSpecialCharacters(c_str(params.specialCharacters));
xmlParserLiaison.SetShouldExpandEntityRefs(params.shouldExpandEntityRefs);
xmlParserLiaison.setUseValidation(params.doValidation);
assert(params.inFileName.size() > 0);
if (!params.setQuietMode)
{
processor.setDiagnosticsOutput(&diagnosticsWriter);
}
XalanDOMString xslFileName;
if(0 != params.xslFileName.size())
{
file://xslFileName = c_str(params.xslFileName);
strcpy(xslFileName,"sample1.xsl");
}
const StylesheetRoot* stylesheet = 0;
if (!isEmpty(xslFileName))
{
stylesheet = processor.processStylesheet(xslFileName, theConstructionContext);
}
XalanAutoPtr<XalanOutputStream> outputFileStream(createOutputStream(params));
assert(outputFileStream.get() != 0);
XalanOutputStreamPrintWriter resultWriter(*outputFileStream.get());
const XalanAutoPtr<FormatterListener> formatter(
createFormatter(
params.outputType,
params.shouldWriteXMLHeader,
params.stripCData,
params.escapeCData,
resultWriter,
xmlParserLiaison.getIndent(),
mimeEncoding,
stylesheet,
xmlParserLiaison));
XSLTResultTarget rTreeTarget;
if(formatter.get() == 0)
{
rTreeTarget.setCharacterStream(&resultWriter);
}
else
{
rTreeTarget.setFormatterListener(formatter.get());
}
// Do the transformation...
// Use the XalanDocument to create an XSLTInputSource object, which
// you can then use in a transformation.
XSLTInputSource theInputSource(theDoc);
StylesheetExecutionContextDefault theExecutionContext(processor,
theXSLProcessorSupport,
theXPathSupport,
theXObjectFactory);
#if defined(XALAN_USE_ICU)
ICUBridgeCollationCompareFunctor theICUFunctor;
theExecutionContext.installCollationCompareFunctor(&theICUFunctor);
#endif
if (stylesheet == 0)
{
// No stylesheet, so our only hope is that the xml file has
// PI with the stylesheet...
// Dummy input source...
XSLTInputSource theStylesheetSource;
processor.process(
theInputSource,
theStylesheetSource,
rTreeTarget,
theConstructionContext,
theExecutionContext);
}
else
{
theExecutionContext.setStylesheetRoot(stylesheet);
processor.process(
theInputSource,
rTreeTarget,
theExecutionContext);
}
if (params.outputType == FormatterListener::OUTPUT_METHOD_DOM)
{
// Output is to DOM, so we have to format to XML to
// produce output...
assert(rTreeTarget.getFormatterListener() != 0 &&
rTreeTarget.getFormatterListener()->getOutputFormat() ==
FormatterListener::OUTPUT_METHOD_DOM);
// Get the FormatterToDOM that produced the result document...
const FormatterToDOM* const theResultFormatter =
#if defined(XALAN_OLD_STYLE_CASTS)
(FormatterToDOM*)rTreeTarget.getFormatterListener();
#else
static_cast<FormatterToDOM*>(rTreeTarget.getFormatterListener());
#endif
// Get the document...
const XalanDocument* const theResultDocument =
theResultFormatter->getDocument();
if (theResultDocument == 0)
{
cerr << endl << "Warning: No DOM document to format!!!" << endl;
}
else
{
// Create a FormaterToDOM with the required output
// options...
const XalanAutoPtr<FormatterListener> formatter(
createFormatter(
FormatterListener::OUTPUT_METHOD_XML,
params.shouldWriteXMLHeader,
params.stripCData,
params.escapeCData,
resultWriter,
xmlParserLiaison.getIndent(),
mimeEncoding,
stylesheet,
xmlParserLiaison));
// Create a FormatterTreeWalker with the the
// new formatter...
FormatterTreeWalker theTreeWalker(*formatter.get());
// Walk the document and produce the XML...
theTreeWalker.traverse(theResultDocument);
}
}
#if !defined(NDEBUG)
if (params.showStats == true)
{
cerr << endl
#if !defined(XALAN_USE_BLOCK_XOBJECT_FACTORY)
<< "Execution XObject details:"
<< endl
<< endl
<< "Total number of XBoolean instances created: "
<< theXObjectFactory.getTotalBooleanInstanceCount()
<< endl
<< "Total number of XNodeSet instances created: "
<< theXObjectFactory.getTotalNodeSetInstanceCount()
<< endl
<< "Total number of XNull instances created: "
<< theXObjectFactory.getTotalNullInstanceCount()
<< endl
<< "Total number of XNumber instances created: "
<< theXObjectFactory.getTotalNumberInstanceCount()
<< endl
<< "Total number of XResultTreeFrag instances created: "
<< theXObjectFactory.getTotalResultTreeFragInstanceCount()
<< endl
<< "Total number of XString instances created: "
<< theXObjectFactory.getTotalStringInstanceCount()
<< endl
<< "Total number of XUnknown instances created: "
<< theXObjectFactory.getTotalUnknownInstanceCount()
<< endl
<< endl
#endif
<< "Execution XPath details:"
<< endl
<< endl
<< "Total number of XPath instances created: "
<< theXPathFactory.getTotalInstanceCount()
<< endl
<< endl
<< endl
<< "Stylesheet XPath details:"
<< endl
<< endl
<< "Total number of XPath instances created: "
<< theStylesheetXPathFactory.getTotalInstanceCount()
<< endl
<< endl;
}
#endif
theExecutionContext.reset();
theConstructionContext.reset();
theStylesheetXPathFactory.reset();
processor.reset();
theXPathFactory.reset();
theXObjectFactory.reset();
theXSLProcessorSupport.reset();
theXPathSupport.reset();
xmlParserLiaison.reset();
return 0;
}
--------------------------------------------------------------------------------