aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dummy/transform.xsl6
-rw-r--r--src/transformation_facade.cc19
-rw-r--r--src/transformation_facade.h4
-rw-r--r--test.cc4
4 files changed, 32 insertions, 1 deletions
diff --git a/dummy/transform.xsl b/dummy/transform.xsl
index c955a85..5e172b6 100644
--- a/dummy/transform.xsl
+++ b/dummy/transform.xsl
@@ -15,11 +15,17 @@
indent="yes"
/>
+<xsl:param name="test"/>
+
<xsl:template match="/">
<html>
<head>
</head>
<body>
+ <div id="parameter">
+ Parameter "test" contains value "<xsl:value-of select="$test"/>"
+ </div>
+
<div id="raw">
<xsl:variable name="testFile" select="InputXSLT:read-file('test.txt')"/>
<xsl:choose>
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
index 846c586..3fee24f 100644
--- a/src/transformation_facade.cc
+++ b/src/transformation_facade.cc
@@ -55,6 +55,7 @@ int TransformationFacade::generate(const std::string& target) {
xalan::XSLTInputSource inputSource(emptyStream);
xalan::XSLTResultTarget outputTarget(target.data());
+
const int resultCode = this->transformer_.transform(
inputSource,
this->transformation_,
@@ -68,4 +69,22 @@ int TransformationFacade::generate(const std::string& target) {
return resultCode;
}
+int TransformationFacade::generate(
+ const std::string& target,
+ const parameter_map& parameters
+) {
+ for ( auto&& parameter : parameters ) {
+ this->transformer_.setStylesheetParam(
+ parameter.first.data(),
+ parameter.second.data()
+ );
+ }
+
+ const int resultCode = this->generate(target);
+
+ this->transformer_.clearStylesheetParams();
+
+ return resultCode;
+}
+
}
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
index 765a376..880335f 100644
--- a/src/transformation_facade.h
+++ b/src/transformation_facade.h
@@ -4,6 +4,7 @@
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <string>
+#include <unordered_map>
#include "common.h"
#include "support/filesystem_context.h"
@@ -12,10 +13,13 @@ namespace InputXSLT {
class TransformationFacade {
public:
+ typedef std::unordered_map<std::string, std::string> parameter_map;
+
TransformationFacade(const std::string&);
~TransformationFacade();
int generate(const std::string&);
+ int generate(const std::string&, const parameter_map&);
private:
const FilesystemContext fs_context_;
diff --git a/test.cc b/test.cc
index f15e1f6..2a6f886 100644
--- a/test.cc
+++ b/test.cc
@@ -5,5 +5,7 @@ int main() {
InputXSLT::PlattformGuard plattform;
InputXSLT::TransformationFacade transformation("../dummy/transform.xsl");
- return transformation.generate("out.xml");
+ return transformation.generate("out.xml", {
+ {"test", "42"}
+ });
}