diff options
author | Adrian Kummerlaender | 2014-12-08 19:28:32 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2014-12-08 19:28:32 +0100 |
commit | 299b5a6d694101be3e053d2a6a680a5ad2d5744b (patch) | |
tree | 99422604cec14f592d04d411e877674d968f64b3 | |
parent | 26c0da85cef1915c06661c913c4f2b5fb695a39f (diff) | |
download | StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.tar StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.tar.gz StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.tar.bz2 StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.tar.lz StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.tar.xz StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.tar.zst StaticXSLT-299b5a6d694101be3e053d2a6a680a5ad2d5744b.zip |
Unraveled recursive call based planning transformation
* eliminated all custom flow control through usage of correctly defined templates called via `apply-templates`
** parameters are passed to the next recursion through a custom `level` node tree
*** this tree may be constructed using `construct_level`
* this approach is more flexible and more in line with how XSLT should be used
** it is now a more direct transformation between the source directory tree and the planned task structure
* analogously to the directory listing which was refactored in `26c0da`
-rw-r--r-- | src/steps/plan.xsl | 156 |
1 files changed, 87 insertions, 69 deletions
diff --git a/src/steps/plan.xsl b/src/steps/plan.xsl index 88ecbdb..ba54aba 100644 --- a/src/steps/plan.xsl +++ b/src/steps/plan.xsl @@ -17,78 +17,100 @@ <xsl:include href="../utility/datasource.xsl"/> -<xsl:template name="traverse"> - <xsl:param name="source"/> - <xsl:param name="target"/> - <xsl:param name="path"/> +<xsl:variable name="source" select="$root/meta/source"/> +<xsl:variable name="target" select="$root/meta/target"/> + +<xsl:template name="construct_level"> <xsl:param name="node"/> + <xsl:param name="path"/> - <xsl:if test="count($node/file | $node/directory) > 0"> - <task type="directory"> - <path> - <xsl:value-of select="concat($target, '/', $path)"/> - </path> - </task> - </xsl:if> - - <xsl:for-each select="$node/file"> - <xsl:choose> - <xsl:when test="@extension = '.xsl'"> - <task type="generate"> - <meta> - <datasource_prefix> - <xsl:value-of select="$target"/> - </datasource_prefix> - </meta> - <source> - <xsl:value-of select="concat($source, '/', $path, '/', @name, @extension)"/> - </source> - <target> - <xsl:value-of select="concat($target, '/', $path)"/> - </target> - </task> - </xsl:when> - <xsl:when test="@extension = '.css'"> - <task type="link"> - <from> - <xsl:value-of select="concat($target, '/', $path, '/', @name, @extension)"/> - </from> - <to> - <xsl:value-of select="concat($source, '/', $path, '/', @name, @extension)"/> - </to> - </task> - </xsl:when> - </xsl:choose> - </xsl:for-each> - - <xsl:for-each select="$node/directory"> - <xsl:choose> - <xsl:when test=".//file/@extension = '.xsl'"> - <xsl:call-template name="traverse"> - <xsl:with-param name="source" select="$source"/> - <xsl:with-param name="target" select="$target"/> - <xsl:with-param name="path" select="concat($path, '/', @name)"/> - <xsl:with-param name="node" select="."/> - </xsl:call-template> - </xsl:when> - <xsl:otherwise> - <task type="link"> - <from> - <xsl:value-of select="concat($target, '/', $path, '/', @name)"/> - </from> - <to> - <xsl:value-of select="concat($source, '/', $path, '/', @name)"/> - </to> - </task> - </xsl:otherwise> - </xsl:choose> - </xsl:for-each> + <level> + <node> + <xsl:copy-of select="$node"/> + </node> + <path> + <xsl:value-of select="$path"/> + </path> + </level> +</xsl:template> + +<xsl:template match="node/file[@extension = '.xsl']"> + <xsl:variable name="base_path" select="../../path"/> + + <task type="generate"> + <meta> + <datasource_prefix> + <xsl:value-of select="$target"/> + </datasource_prefix> + </meta> + <source> + <xsl:value-of select="concat($source, '/', $base_path, '/', @name, @extension)"/> + </source> + <target> + <xsl:value-of select="concat($target, '/', $base_path)"/> + </target> + </task> +</xsl:template> + +<xsl:template match="node/file[@extension = '.css']"> + <xsl:variable name="base_path" select="../../path"/> + + <task type="link"> + <from> + <xsl:value-of select="concat($target, '/', $base_path, '/', @name, @extension)"/> + </from> + <to> + <xsl:value-of select="concat($source, '/', $base_path, '/', @name, @extension)"/> + </to> + </task> +</xsl:template> + +<xsl:template match="node/directory[.//file/@extension = '.xsl']"> + <xsl:variable name="base_path" select="../../path"/> + + <xsl:variable name="new_level"> + <xsl:call-template name="construct_level"> + <xsl:with-param name="path" select="concat($base_path, '/', @name)"/> + <xsl:with-param name="node" select="./node()"/> + </xsl:call-template> + </xsl:variable> + + <xsl:apply-templates select="xalan:nodeset($new_level)/level"/> +</xsl:template> + +<xsl:template match="node/directory[not(.//file/@extension = '.xsl')]"> + <xsl:variable name="base_path" select="../../path"/> + + <task type="link"> + <from> + <xsl:value-of select="concat($target, '/', $base_path, '/', @name)"/> + </from> + <to> + <xsl:value-of select="concat($source, '/', $base_path, '/', @name)"/> + </to> + </task> +</xsl:template> + +<xsl:template match="level[count(node/file | node/directory) > 0]"> + <task type="directory"> + <path> + <xsl:value-of select="concat($target, '/', path)"/> + </path> + </task> + + <xsl:apply-templates select="node/file | node/directory"/> </xsl:template> <xsl:template match="datasource"> <xsl:copy-of select="source"/> <xsl:copy-of select="meta"/> + <xsl:variable name="new_level"> + <xsl:call-template name="construct_level"> + <xsl:with-param name="node" select="source/node()"/> + </xsl:call-template> + </xsl:variable> + <tasks> <task type="clean"> <path> @@ -96,11 +118,7 @@ </path> </task> - <xsl:call-template name="traverse"> - <xsl:with-param name="source" select="$root/meta/source"/> - <xsl:with-param name="target" select="$root/meta/target"/> - <xsl:with-param name="node" select="source"/> - </xsl:call-template> + <xsl:apply-templates select="xalan:nodeset($new_level)/level"/> </tasks> </xsl:template> |