diff options
| author | Adrian Kummerlaender | 2014-07-10 20:24:31 +0200 | 
|---|---|---|
| committer | Adrian Kummerlaender | 2014-07-10 20:24:31 +0200 | 
| commit | 2192896e08572419edf99c81c3a524f07e877a10 (patch) | |
| tree | b51c538c84e713e58b42c099fc0c4e0a89d8893e | |
| parent | 1fbf6a39784b57925ab19df579f487a338e22ba5 (diff) | |
| download | InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.tar InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.tar.gz InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.tar.bz2 InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.tar.lz InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.tar.xz InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.tar.zst InputXSLT-2192896e08572419edf99c81c3a524f07e877a10.zip | |
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
| -rw-r--r-- | src/transformer_facade.cc | 87 | ||||
| -rw-r--r-- | 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 <xalanc/PlatformSupport/XalanOutputStreamPrintWriter.hpp>  #include <xalanc/PlatformSupport/XalanStdOutputStream.hpp> +#include <xalanc/XSLT/StylesheetRoot.hpp> +#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>  #include <xalanc/XMLSupport/FormatterToXML.hpp>  #include <xalanc/XercesParserLiaison/FormatterToXercesDOM.hpp>  #include <xalanc/XMLSupport/FormatterTreeWalker.hpp> @@ -14,6 +16,41 @@  #include "support/xerces_string_guard.h"  #include "support/dom/document_cache.h" +namespace { + +std::unique_ptr<xalan::FormatterToXML> 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<xalan::FormatterToXML>( +		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 <typename Source> +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 <typename Source> +		void dispatchTransformer( +			const Source&, +			const xalan::XSLTInputSource&, +			xalan::FormatterListener& +		); + +  };  } | 
