From 2192896e08572419edf99c81c3a524f07e877a10 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 10 Jul 2014 20:24:31 +0200 Subject: Fixed TransformerFacade doctype output for xalan::FormatterToXML * "xsl:output" was disregarded for xalan::FormatterToXML based output ** the setting contained within this tag have to be passed manually to the constructor... ** the xalan standard implementation includes special handling for this case ** sadly there was no alternative to adding special handling in InputXSLT as well, it is really quite ugly * added "dispatchTransformer" template member method to TransformerFacade ** calls xalan::FormatterToXML augmentation logic if needed, compiles template * this problem also exists for FunctionTransform output to xercesc DOM ** this patch doesn't aim to fix it in that case, it will have to be fixed separately --- src/transformer_facade.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++-- src/transformer_facade.h | 8 +++++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc index 76b68d6..5910bc7 100644 --- a/src/transformer_facade.cc +++ b/src/transformer_facade.cc @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include #include @@ -14,6 +16,41 @@ #include "support/xerces_string_guard.h" #include "support/dom/document_cache.h" +namespace { + +std::unique_ptr augmentFormatterToXML( + const xalan::XalanCompiledStylesheet* const transformation, + xalan::FormatterListener& formatter +) { + const xalan::StylesheetRoot* const stylesheetRoot( + transformation->getStylesheetRoot() + ); + + xalan::XalanDOMString outputVersion; + xalan::XalanDOMString outputEncoding; + xalan::XalanDOMString outputMediaType; + xalan::XalanDOMString outputDoctypePublic; + xalan::XalanDOMString outputDoctypeSystem; + xalan::XalanDOMString outputStandalone; + + return std::unique_ptr( + new xalan::FormatterToXML( + *(formatter.getWriter()), + stylesheetRoot->getOutputVersion(outputVersion), + stylesheetRoot->getOutputIndent(), + 0, + stylesheetRoot->getOutputEncoding(outputEncoding), + stylesheetRoot->getOutputMediaType(outputMediaType), + stylesheetRoot->getOutputDoctypePublic(outputDoctypePublic), + stylesheetRoot->getOutputDoctypeSystem(outputDoctypeSystem), + !stylesheetRoot->getOmitOutputXMLDecl(), + stylesheetRoot->getOutputStandalone(outputStandalone) + ) + ); +} + +} + namespace InputXSLT { TransformerFacade::TransformerFacade(IncludeEntityResolver* resolver): @@ -35,7 +72,7 @@ void TransformerFacade::generate( if ( source.getNode() == nullptr ) { ErrorCapacitor errorCapacitor(&this->error_multiplexer_); - this->transformer_.transform( + this->dispatchTransformer( source, transformation, target @@ -70,7 +107,7 @@ void TransformerFacade::generate( domSupport ); - this->transformer_.transform( + this->dispatchTransformer( inputParsedSource, transformation, target @@ -107,7 +144,7 @@ void TransformerFacade::generate( domSupport ); - this->transformer_.transform( + this->dispatchTransformer( inputParsedSource, transformation, target @@ -116,4 +153,48 @@ void TransformerFacade::generate( errorCapacitor.discharge(); } +template +void TransformerFacade::dispatchTransformer( + const Source& source, + const xalan::XSLTInputSource& transformation, + xalan::FormatterListener& target +) { + const xalan::XalanCompiledStylesheet* compiledTransformation{}; + + this->transformer_.compileStylesheet( + transformation, + compiledTransformation + ); + + switch ( target.getOutputFormat() ) { + case xalan::FormatterListener::eFormat::OUTPUT_METHOD_XML: { + auto formatter = augmentFormatterToXML( + compiledTransformation, + target + ); + + this->transformer_.transform( + source, + compiledTransformation, + *formatter + ); + + break; + } + default: { + this->transformer_.transform( + source, + compiledTransformation, + target + ); + + break; + } + } + + this->transformer_.destroyStylesheet( + compiledTransformation + ); +} + } diff --git a/src/transformer_facade.h b/src/transformer_facade.h index 17db094..14d2f41 100644 --- a/src/transformer_facade.h +++ b/src/transformer_facade.h @@ -39,6 +39,14 @@ class TransformerFacade { xalan::FormatterListener& ); + template + void dispatchTransformer( + const Source&, + const xalan::XSLTInputSource&, + xalan::FormatterListener& + ); + + }; } -- cgit v1.2.3