aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-16 22:25:39 +0200
committerAdrian Kummerländer2014-05-16 22:25:39 +0200
commit7bd543e220c806177d805a8f4fbc13e951fe5788 (patch)
tree0fe8746d3ae922340a8fed56db7e112cd63dc811
parentec6abad74348e9b577e1dd63b41d65263bb0334a (diff)
downloadInputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.tar
InputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.tar.gz
InputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.tar.bz2
InputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.tar.lz
InputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.tar.xz
InputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.tar.zst
InputXSLT-7bd543e220c806177d805a8f4fbc13e951fe5788.zip
Added XObjectPtr parameter to FunctionTransform
* the given XObject is passed to the called transformation ** this was done to enable templates to pass information to each other ** this should support any type usable in a XPath context to be passed as an argument * expanded FunctionTransform test case accordingly
-rw-r--r--src/function/base.h2
-rw-r--r--src/function/transform.cc3
-rw-r--r--src/function/transform.h3
-rw-r--r--src/support/stylesheet_parameter_guard.cc10
-rw-r--r--src/support/stylesheet_parameter_guard.h2
-rw-r--r--src/support/tuple/mapper.h2
-rw-r--r--src/support/tuple/xobject_value.cc5
-rw-r--r--src/transformation_facade.cc10
-rw-r--r--src/transformation_facade.h6
-rw-r--r--test/transform/reference.xml19
-rw-r--r--test/transform/test.xsl12
-rw-r--r--test/transform/transformation.xsl12
12 files changed, 69 insertions, 17 deletions
diff --git a/src/function/base.h b/src/function/base.h
index b74a7d8..8145924 100644
--- a/src/function/base.h
+++ b/src/function/base.h
@@ -81,7 +81,7 @@ class FunctionBase : public xalan::Function {
result.assign(std::string(
"The function expects " +
std::to_string(std::tuple_size<argument_tuple>::value) +
- " argument(s) of type string."
+ " argument(s)"
).data());
return result;
diff --git a/src/function/transform.cc b/src/function/transform.cc
index be06037..4f9aecc 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -38,7 +38,8 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
);
const int result = transformation.generate(
- targetPath.string()
+ targetPath.string(),
+ std::get<2>(arguments)
);
if ( result == 0 ) {
diff --git a/src/function/transform.h b/src/function/transform.h
index 2be8925..f010596 100644
--- a/src/function/transform.h
+++ b/src/function/transform.h
@@ -8,7 +8,8 @@ namespace InputXSLT {
class FunctionTransform : public FunctionBase<
FunctionTransform,
std::string,
- std::string
+ std::string,
+ xalan::XObjectPtr
> {
public:
using FunctionBase::FunctionBase;
diff --git a/src/support/stylesheet_parameter_guard.cc b/src/support/stylesheet_parameter_guard.cc
index f82c2d5..399bccb 100644
--- a/src/support/stylesheet_parameter_guard.cc
+++ b/src/support/stylesheet_parameter_guard.cc
@@ -33,4 +33,14 @@ void StylesheetParameterGuard::set(
);
}
+void StylesheetParameterGuard::set(
+ const std::string& key,
+ const xalan::XObjectPtr& value
+) {
+ this->transformer_.setStylesheetParam(
+ key.data(),
+ value
+ );
+}
+
}
diff --git a/src/support/stylesheet_parameter_guard.h b/src/support/stylesheet_parameter_guard.h
index f0622ad..7fa425e 100644
--- a/src/support/stylesheet_parameter_guard.h
+++ b/src/support/stylesheet_parameter_guard.h
@@ -2,6 +2,7 @@
#define INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+#include <xalanc/XPath/XObject.hpp>
#include <string>
#include <unordered_map>
@@ -24,6 +25,7 @@ class StylesheetParameterGuard {
void set(const map&);
void set(const std::string&, const std::string&);
+ void set(const std::string&, const xalan::XObjectPtr&);
private:
xalan::XalanTransformer& transformer_;
diff --git a/src/support/tuple/mapper.h b/src/support/tuple/mapper.h
index c95365e..28c5f3b 100644
--- a/src/support/tuple/mapper.h
+++ b/src/support/tuple/mapper.h
@@ -55,7 +55,7 @@ namespace Mapper {
)
);
}
-};
+}
}
diff --git a/src/support/tuple/xobject_value.cc b/src/support/tuple/xobject_value.cc
index 3883436..fac4d96 100644
--- a/src/support/tuple/xobject_value.cc
+++ b/src/support/tuple/xobject_value.cc
@@ -13,6 +13,11 @@ std::string get<std::string>(const xalan::XObjectPtr& ptr) {
return toString(ptr->str());
}
+template <>
+xalan::XObjectPtr get<xalan::XObjectPtr>(const xalan::XObjectPtr& ptr) {
+ return ptr;
+}
+
}
}
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
index 698cdb1..8e99179 100644
--- a/src/transformation_facade.cc
+++ b/src/transformation_facade.cc
@@ -42,6 +42,16 @@ int TransformationFacade::generate(
int TransformationFacade::generate(
const std::string& target,
+ const xalan::XObjectPtr& argument
+) {
+ StylesheetParameterGuard guard(this->transformer_);
+ guard.set("arguments", argument);
+
+ return this->generate(target, guard);
+}
+
+int TransformationFacade::generate(
+ const std::string& target,
StylesheetParameterGuard& parameters
) {
const boost::filesystem::path targetFilePath(
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
index 3172daa..be06d07 100644
--- a/src/transformation_facade.h
+++ b/src/transformation_facade.h
@@ -16,10 +16,8 @@ class TransformationFacade {
~TransformationFacade();
int generate(const std::string&);
- int generate(
- const std::string&,
- const StylesheetParameterGuard::map&
- );
+ int generate(const std::string&, const StylesheetParameterGuard::map&);
+ int generate(const std::string&, const xalan::XObjectPtr&);
private:
const xalan::XalanCompiledStylesheet* transformation_;
diff --git a/test/transform/reference.xml b/test/transform/reference.xml
index 37c060e..d3675bc 100644
--- a/test/transform/reference.xml
+++ b/test/transform/reference.xml
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<test_case>
-<transform>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
+<transform>
+<transform_test>
+<argument_value>42</argument_value>
+<transformation_content>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
xmlns:InputXSLT="function.inputxslt.application"
- exclude-result-prefixes="InputXSLT"
+ exclude-result-prefixes="InputXSLT xalan"
&gt;
&lt;xsl:output
@@ -18,12 +22,17 @@
&lt;xsl:template match="/"&gt;
&lt;test_case&gt;
&lt;transform&gt;
+ &lt;xsl:variable name="argument"&gt;
+ &lt;key&gt;test&lt;/key&gt;
+ &lt;value&gt;42&lt;/value&gt;
+ &lt;/xsl:variable&gt;
+
&lt;xsl:variable
name = "result"
- select = "InputXSLT:transform('test.xsl', 'test_actual.xml')"
+ select = "InputXSLT:transform('test.xsl', 'test_actual.xml', $argument)"
/&gt;
- &lt;xsl:value-of select="
+ &lt;xsl:copy-of select="
InputXSLT:read-xml-file('test_actual.xml')/test_case/transform_test
"/&gt;
&lt;/transform&gt;
@@ -31,5 +40,7 @@
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
+</transformation_content>
+</transform_test>
</transform>
</test_case>
diff --git a/test/transform/test.xsl b/test/transform/test.xsl
index 40134c4..677e80d 100644
--- a/test/transform/test.xsl
+++ b/test/transform/test.xsl
@@ -2,8 +2,9 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
xmlns:InputXSLT="function.inputxslt.application"
- exclude-result-prefixes="InputXSLT"
+ exclude-result-prefixes="InputXSLT xalan"
>
<xsl:output
@@ -13,10 +14,17 @@
indent="yes"
/>
+<xsl:param name="arguments"/>
+
<xsl:template match="/">
<test_case>
<transform_test>
- <xsl:value-of select="InputXSLT:read-file('transformation.xsl')"/>
+ <argument_value>
+ <xsl:value-of select="xalan:nodeset($arguments)/value"/>
+ </argument_value>
+ <transformation_content>
+ <xsl:value-of select="InputXSLT:read-file('transformation.xsl')"/>
+ </transformation_content>
</transform_test>
</test_case>
</xsl:template>
diff --git a/test/transform/transformation.xsl b/test/transform/transformation.xsl
index 9039642..7348fef 100644
--- a/test/transform/transformation.xsl
+++ b/test/transform/transformation.xsl
@@ -2,8 +2,9 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
xmlns:InputXSLT="function.inputxslt.application"
- exclude-result-prefixes="InputXSLT"
+ exclude-result-prefixes="InputXSLT xalan"
>
<xsl:output
@@ -16,12 +17,17 @@
<xsl:template match="/">
<test_case>
<transform>
+ <xsl:variable name="argument">
+ <key>test</key>
+ <value>42</value>
+ </xsl:variable>
+
<xsl:variable
name = "result"
- select = "InputXSLT:transform('test.xsl', 'test_actual.xml')"
+ select = "InputXSLT:transform('test.xsl', 'test_actual.xml', $argument)"
/>
- <xsl:value-of select="
+ <xsl:copy-of select="
InputXSLT:read-xml-file('test_actual.xml')/test_case/transform_test
"/>
</transform>