diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | test/read_directory/reference.xml | 3 | ||||
-rw-r--r-- | test/transform/transformation.xsl | 14 | ||||
-rw-r--r-- | test/write_file/reference.xml | 3 | ||||
-rw-r--r-- | test/write_file/transformation.xsl | 26 |
5 files changed, 41 insertions, 9 deletions
@@ -1,6 +1,6 @@ # InputXSLT -... is a proof-of-concept implementation of external read-only file access functions for XSLT based on Apache [xalan](https://xalan.apache.org/) and [xerces](https://xerces.apache.org/). +... is a proof-of-concept implementation of external ~~read-only~~ file access functions for XSLT based on Apache [xalan](https://xalan.apache.org/) and [xerces](https://xerces.apache.org/). ## Why?! @@ -9,6 +9,8 @@ Contrary to popular opinion I actually like XSLT as a content transformation lan ## Current features: - external `read-file` function for read-only access to both plain and xml files +- external `write-file` function for writing files +- external `read-directory` function for read-only directory traversal - external `read-directory` function for read-only directory traversal - external `transform` function for executing transformations inside transformations - external `external-text-formatter` function for executing text formatters and capturing their XML output diff --git a/test/read_directory/reference.xml b/test/read_directory/reference.xml index 4c1000b..b2eac35 100644 --- a/test/read_directory/reference.xml +++ b/test/read_directory/reference.xml @@ -28,4 +28,7 @@ <item type="directory"> <name>transform</name> </item> +<item type="directory"> +<name>write_file</name> +</item> </test_case> diff --git a/test/transform/transformation.xsl b/test/transform/transformation.xsl index 99933ba..ba17981 100644 --- a/test/transform/transformation.xsl +++ b/test/transform/transformation.xsl @@ -14,9 +14,7 @@ <xsl:param name="transformation"/> <xsl:param name="parameters"/> - <xsl:variable name="stylesheet" select=" - InputXSLT:read-file(string($transformation)) - "/> + <xsl:variable name="stylesheet" select="InputXSLT:read-file($transformation)"/> <xsl:choose> <xsl:when test="$stylesheet/self::file/@result = 'success'"> @@ -53,15 +51,15 @@ <xsl:when test="xalan:nodeset($result)/transformation/@result = 'success'"> <xsl:variable name="writeResult" select=" InputXSLT:write-file( - string($target), + $target, xalan:nodeset($result)/transformation/text() ) "/> - <transformation result="success" target="{$target}"/> + <generator result="success" target="{$target}"/> </xsl:when> <xsl:otherwise> - <transformation result="error" target="{$target}"/> + <generator result="error" target="{$target}"/> </xsl:otherwise> </xsl:choose> </xsl:template> @@ -78,13 +76,13 @@ </xsl:variable> <xsl:choose> - <xsl:when test="xalan:nodeset($result)/transformation/@result = 'success'"> + <xsl:when test="xalan:nodeset($result)/generator/@result = 'success'"> <xsl:copy-of select=" InputXSLT:read-file('test_actual.xml')/test_case/transform_test/* "/> </xsl:when> <xsl:otherwise> - <xsl:copy-of select="xalan:nodeset($result)/transformation/*"/> + <xsl:copy-of select="xalan:nodeset($result)/generator/*"/> </xsl:otherwise> </xsl:choose> </xsl:template> diff --git a/test/write_file/reference.xml b/test/write_file/reference.xml new file mode 100644 index 0000000..ba10cf5 --- /dev/null +++ b/test/write_file/reference.xml @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="UTF-8"?> +<test_case>Hello world! +</test_case> diff --git a/test/write_file/transformation.xsl b/test/write_file/transformation.xsl new file mode 100644 index 0000000..f65e62d --- /dev/null +++ b/test/write_file/transformation.xsl @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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 xalan" +> + +<xsl:import href="[testcase.xsl]"/> + +<xsl:template name="implementation"> + <xsl:variable name="result" select="InputXSLT:write-file('test.txt', 'Hello world!')"/> + <xsl:variable name="content" select="InputXSLT:read-file('test.txt')"/> + + <xsl:choose> + <xsl:when test="$content/self::file/@result = 'success'"> + <xsl:value-of select="$content/self::file/text()"/> + </xsl:when> + <xsl:otherwise> + Error during file io + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> |