diff options
-rw-r--r-- | ixslt.cc | 6 | ||||
-rw-r--r-- | src/function/read_file.cc | 3 | ||||
-rw-r--r-- | src/function/transform.cc | 4 | ||||
-rw-r--r-- | src/function/transform.h | 6 | ||||
-rw-r--r-- | src/support/type/xobject_value.cc | 19 | ||||
-rw-r--r-- | src/transformation_facade.cc | 53 | ||||
-rw-r--r-- | src/transformation_facade.h | 23 | ||||
-rw-r--r-- | test/transform/transformation.xsl | 2 |
8 files changed, 83 insertions, 33 deletions
@@ -100,14 +100,14 @@ bool process(const boost::program_options::variables_map& variables) { if ( variables.count("input") ) { transformation = InputXSLT::TransformationFacade::try_create( handleErrors, - variables["input"].as<std::string>(), - variables["transformation"].as<std::string>(), + variables["input"].as<std::string>().data(), + variables["transformation"].as<std::string>().data(), plattform.getEntityResolver() ); } else { transformation = InputXSLT::TransformationFacade::try_create( handleErrors, - variables["transformation"].as<std::string>(), + variables["transformation"].as<std::string>().data(), plattform.getEntityResolver() ); } diff --git a/src/function/read_file.cc b/src/function/read_file.cc index 7603ad1..1ea76c7 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -14,7 +14,8 @@ namespace { inline bool isXmlFile(const boost::filesystem::path& filePath) { - return filePath.extension() == ".xml"; + return filePath.extension() == ".xml" || + filePath.extension() == ".xsl"; } inline xercesc::DOMNode* readXmlFile( diff --git a/src/function/transform.cc b/src/function/transform.cc index 9f0e98a..62b89ba 100644 --- a/src/function/transform.cc +++ b/src/function/transform.cc @@ -30,7 +30,7 @@ namespace InputXSLT { xercesc::DOMDocument* FunctionTransform::constructDocument( const InputXSLT::FilesystemContext& fsContext, - std::string transformationPath, + xalan::XSLTInputSource transformationSource, std::string targetPath, xalan::XObjectPtr parameterObject ) { @@ -55,7 +55,7 @@ xercesc::DOMDocument* FunctionTransform::constructDocument( if ( auto transformation = TransformationFacade::try_create( handleErrors(result), - fsContext.resolve(transformationPath).string(), + transformationSource, this->include_resolver_ ) ) { try { diff --git a/src/function/transform.h b/src/function/transform.h index b841750..081fe90 100644 --- a/src/function/transform.h +++ b/src/function/transform.h @@ -1,13 +1,15 @@ #ifndef INPUTXSLT_SRC_FUNCTION_TRANSFORM_H_ #define INPUTXSLT_SRC_FUNCTION_TRANSFORM_H_ +#include <xalanc/XSLT/XSLTInputSource.hpp> + #include "base.h" namespace InputXSLT { class FunctionTransform : public FunctionBase< FunctionTransform, - std::string, + xalan::XSLTInputSource, std::string, xalan::XObjectPtr > { @@ -19,7 +21,7 @@ class FunctionTransform : public FunctionBase< xercesc::DOMDocument* constructDocument( const FilesystemContext&, - std::string, + xalan::XSLTInputSource, std::string, xalan::XObjectPtr ); diff --git a/src/support/type/xobject_value.cc b/src/support/type/xobject_value.cc index cdeb9c6..812be52 100644 --- a/src/support/type/xobject_value.cc +++ b/src/support/type/xobject_value.cc @@ -1,5 +1,8 @@ #include "xobject_value.h" +#include <xalanc/XSLT/XSLTInputSource.hpp> +#include <xalanc/XalanDOM/XalanDocumentFragment.hpp> + #include <boost/algorithm/string.hpp> #include <string> @@ -20,6 +23,22 @@ xalan::XObjectPtr get<xalan::XObjectPtr>(const xalan::XObjectPtr& ptr) { return ptr; } +template <> +xalan::XSLTInputSource get<xalan::XSLTInputSource>( + const xalan::XObjectPtr& ptr) { + switch ( ptr->getType() ) { + case xalan::XObject::eObjectType::eTypeNodeSet: { + return xalan::XSLTInputSource(ptr->nodeset().item(0)); + } + case xalan::XObject::eObjectType::eTypeResultTreeFrag: { + return xalan::XSLTInputSource(ptr->rtree().getFirstChild()); + } + default: { + return xalan::XSLTInputSource(ptr->str()); + } + } +} + } } diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 16872c7..93d14ea 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -7,21 +7,41 @@ #include <sstream> +#include "support/xerces_string_guard.h" + namespace InputXSLT { TransformationFacade::TransformationFacade( - const std::string& transformation, + xalan::XSLTInputSource transformation, IncludeEntityResolver* resolver ): - TransformationFacade( - std::string{}, + input_{}, + transformation_{}, + transformer_(), + error_multiplexer_(&transformer_), + warning_capacitor_(&error_multiplexer_) { + this->transformer_.setEntityResolver(resolver); + + ErrorCapacitor errorCapacitor(&this->error_multiplexer_); + + std::stringstream dummyStream("<dummy/>"); + + this->transformer_.parseSource( + xalan::XSLTInputSource(dummyStream), + this->input_ + ); + + this->transformer_.compileStylesheet( transformation, - resolver - ) { } + this->transformation_ + ); + + errorCapacitor.discharge(); +} TransformationFacade::TransformationFacade( - const std::string& input, - const std::string& transformation, + xalan::XSLTInputSource input, + xalan::XSLTInputSource transformation, IncludeEntityResolver* resolver ): input_{}, @@ -33,22 +53,13 @@ TransformationFacade::TransformationFacade( ErrorCapacitor errorCapacitor(&this->error_multiplexer_); - if ( input.empty() ) { - std::stringstream dummyStream("<dummy/>"); - - this->transformer_.parseSource( - xalan::XSLTInputSource(dummyStream), - this->input_ - ); - } else { - this->transformer_.parseSource( - xalan::XSLTInputSource(input.data()), - this->input_ - ); - } + this->transformer_.parseSource( + input, + this->input_ + ); this->transformer_.compileStylesheet( - xalan::XSLTInputSource(transformation.data()), + transformation, this->transformation_ ); diff --git a/src/transformation_facade.h b/src/transformation_facade.h index fe711bc..ca72c90 100644 --- a/src/transformation_facade.h +++ b/src/transformation_facade.h @@ -26,10 +26,17 @@ class TransformationFacade { Arguments&&... ); - TransformationFacade(const std::string&, IncludeEntityResolver*); + template<typename... Arguments> + TransformationFacade(Arguments&&..., IncludeEntityResolver*); + TransformationFacade( - const std::string&, - const std::string&, + xalan::XSLTInputSource, + IncludeEntityResolver* + ); + + TransformationFacade( + xalan::XSLTInputSource, + xalan::XSLTInputSource, IncludeEntityResolver* ); @@ -79,6 +86,16 @@ auto TransformationFacade::try_create( } } +template <typename... Arguments> +TransformationFacade::TransformationFacade( + Arguments&&... arguments, + IncludeEntityResolver* resolver +): + TransformationFacade( + xalan::XSLTInputSource(std::forward<Arguments>(arguments))..., + resolver + ) { } + template <typename Target> void TransformationFacade::generate(Target& target) { StylesheetParameterGuard guard(this->transformer_); diff --git a/test/transform/transformation.xsl b/test/transform/transformation.xsl index 0c6173d..fb7bf65 100644 --- a/test/transform/transformation.xsl +++ b/test/transform/transformation.xsl @@ -17,7 +17,7 @@ <xsl:variable name="command"> InputXSLT:transform( - $transformation, + string($transformation), $target, xalan:nodeset($parameters) ) |