diff options
author | Adrian Kummerländer | 2014-04-24 20:14:14 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-24 20:14:14 +0200 |
commit | a31fc1169edb33126242eb035dc038cbdea407e8 (patch) | |
tree | bba9d219ad9fc8a0ea752f6d8025a4b614bdebdb /src/transformation_facade.cc | |
parent | 525aa8c4dc3e23f0369c7edb1fb507ecad5f43bf (diff) | |
download | InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.gz InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.bz2 InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.lz InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.xz InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.zst InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.zip |
Changed TransformerFacade into TransformationFacade for single XSLTs
* contains a single, compiled transformation as specified by its construction argument
* uses the transformation's location as the FilesystemContext
* allows generation of output documents using _generate_ member method
Diffstat (limited to 'src/transformation_facade.cc')
-rw-r--r-- | src/transformation_facade.cc | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc new file mode 100644 index 0000000..58bdb52 --- /dev/null +++ b/src/transformation_facade.cc @@ -0,0 +1,65 @@ +#include "transformation_facade.h" + +#include <xalanc/XSLT/XSLTInputSource.hpp> +#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp> + +#include <sstream> + +#include "function/read_file.h" +#include "function/read_xml_file.h" +#include "function/read_directory.h" + + +namespace InputXSLT { + +TransformationFacade::TransformationFacade(const std::string& transformation): + fs_context_(boost::filesystem::path(transformation).parent_path().string()), + transformation_{}, + transformer_() { + const xalan::XalanDOMString customNamespace( + "http://ExternalFunction.xalan-c++.xml.apache.org" + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-file"), + InputXSLT::FunctionReadFile(this->fs_context_) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-xml-file"), + InputXSLT::FunctionReadXmlFile(this->fs_context_) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-directory"), + InputXSLT::FunctionReadDirectory(this->fs_context_) + ); + + this->transformer_.compileStylesheet( + xalan::XSLTInputSource(transformation.data()), + this->transformation_ + ); +} + +TransformationFacade::~TransformationFacade() { + this->transformer_.destroyStylesheet( + this->transformation_ + ); +} + +int TransformationFacade::generate(const std::string& target) { + std::stringstream emptyStream("<dummy/>"); + xalan::XSLTInputSource inputSource(emptyStream); + xalan::XSLTResultTarget outputTarget(target.data()); + + return this->transformer_.transform( + inputSource, + this->transformation_, + outputTarget + ); +} + +} |