aboutsummaryrefslogtreecommitdiff
path: root/test/generate
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-07-12 16:15:42 +0200
committerAdrian Kummerlaender2014-07-12 16:15:42 +0200
commit086779c6d3d40f244b6aafd6d402fd29b921a735 (patch)
treec606a54c92f9b638797a95437adfe0a6fee05030 /test/generate
parent141725d681dd69f77e993c3d59d613d1ad7014f9 (diff)
downloadInputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.tar
InputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.tar.gz
InputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.tar.bz2
InputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.tar.lz
InputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.tar.xz
InputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.tar.zst
InputXSLT-086779c6d3d40f244b6aafd6d402fd29b921a735.zip
Implemented external "generate" function
* this function essentially provides the same functionality as FunctionTransform with the addition of directly committing the result to the filesystem ** this is needed if one wants to generate doctype-containing transformations from inside a transformation as "write-file" is not able to infer the doctype of a given xalan::XalanNode pointer ** this is a integral limitation of (at least) XSLT 1.0 as implemented in Apache Xalan *** a document can of course only have a single document type *** e.g. we can not include a doctype node in the result tree of FunctionTransform * implemented test case for FunctionGenerate * transformation "test.xsl" is shared between the FunctionTransform and FunctionGenerate test cases * modified README.md accordingly
Diffstat (limited to 'test/generate')
-rw-r--r--test/generate/reference.xml10
-rw-r--r--test/generate/transformation.xsl58
2 files changed, 68 insertions, 0 deletions
diff --git a/test/generate/reference.xml b/test/generate/reference.xml
new file mode 100644
index 0000000..1c702e8
--- /dev/null
+++ b/test/generate/reference.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test_case>
+<input_entries>
+<entry>Hello 1</entry>
+<entry>Hello 2</entry>
+<entry>Hello 3</entry>
+<entry>Hello 4</entry>
+</input_entries>
+<parameter_value>42</parameter_value>
+</test_case>
diff --git a/test/generate/transformation.xsl b/test/generate/transformation.xsl
new file mode 100644
index 0000000..6e3d88b
--- /dev/null
+++ b/test/generate/transformation.xsl
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+ version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:dyn="http://exslt.org/dynamic"
+ xmlns:xalan="http://xml.apache.org/xalan"
+ xmlns:InputXSLT="function.inputxslt.application"
+ exclude-result-prefixes="dyn xalan InputXSLT"
+>
+
+<xsl:import href="[testcase.xsl]"/>
+
+<xsl:template name="generator">
+ <xsl:param name="input"/>
+ <xsl:param name="transformation"/>
+ <xsl:param name="target"/>
+
+ <xsl:copy-of select="InputXSLT:generate(
+ $input,
+ string($transformation),
+ string($target)
+ )"/>
+</xsl:template>
+
+<xsl:template name="implementation">
+ <xsl:variable name="result">
+ <xsl:call-template name="generator">
+ <xsl:with-param name="input">
+ <test>
+ <entries>
+ <entry>Hello 1</entry>
+ <entry>Hello 2</entry>
+ <entry>Hello 3</entry>
+ <entry>Hello 4</entry>
+ </entries>
+ <parameter>
+ <test>21</test>
+ </parameter>
+ </test>
+ </xsl:with-param>
+ <xsl:with-param name="transformation">[test.xsl]</xsl:with-param>
+ <xsl:with-param name="target">test_actual.xml</xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="generation" select="xalan:nodeset($result)/generation"/>
+
+ <xsl:choose>
+ <xsl:when test="$generation/@result = 'success'">
+ <xsl:copy-of select="InputXSLT:read-file('test_actual.xml')/test_case/transform_test/*"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="$generation/*"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>