diff options
author | Adrian Kummerlaender | 2014-10-11 23:31:38 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-10-11 23:31:38 +0200 |
commit | c8bf8044eed7df60bfc645097df90dd111554f2f (patch) | |
tree | 252263a55c5e315e7fed9c1eced7e238c9adfe2d | |
parent | 4d3fae9134a0bcfcc7e95a690c65bf1ceb613229 (diff) | |
download | BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.tar BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.tar.gz BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.tar.bz2 BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.tar.lz BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.tar.xz BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.tar.zst BuildXSLT-c8bf8044eed7df60bfc645097df90dd111554f2f.zip |
Implemented module support
* module support aims to enable extraction of core static site generation functionality implemented for my personal blog into a separate project
** i.e. the detail transformations of repository [blog.kummerlaender.eu](https://github.com/KnairdA/blog.kummerlaender.eu/)
* a BuildXSLT module is a simple XML file definining the transformations which make up the module
* modules may be built using the newly implemented "module" task type
** this task requires a input and definition node
*** the input node is resolved in the same way as "generate" input nodes
*** the definition node currently only supports the file mode
** chained transformation links inside the definition are resolved relative to the definition files location
*** this was enabled by commit `a4a7ee4` to InputXSLT
* restructured task processing
* transformations are now read by "InputXSLT:generate" instead of by "InputXSLT:read-file"
** this enables entities to be resolved against the transformation location
** this was enabled through filesystem context resolution changes in commit `3c166ed` to InputXSLT
* added basic error handling based on terminating XSLT messages
-rw-r--r-- | build.xsl | 190 |
1 files changed, 176 insertions, 14 deletions
@@ -18,10 +18,23 @@ <xsl:param name="input"/> <xsl:param name="transformation"/> - <xsl:copy-of select="InputXSLT:generate( + <xsl:variable name="result" select="InputXSLT:generate( xalan:nodeset($input), - InputXSLT:read-file(string($transformation))/self::file/node() - )/self::generation/node()"/> + string($transformation) + )/self::generation"/> + + <xsl:choose> + <xsl:when test="$result/@result = 'success'"> + <xsl:copy-of select="$result/node()"/> + </xsl:when> + <xsl:otherwise> + <xsl:message terminate="yes"> + <xsl:text>Failed to generate transformation "</xsl:text> + <xsl:value-of select="string($transformation)"/> + <xsl:text>"</xsl:text> + </xsl:message> + </xsl:otherwise> + </xsl:choose> </xsl:template> <xsl:template name="generate_chain"> @@ -51,22 +64,97 @@ </xsl:choose> </xsl:template> -<xsl:template match="task[@type = 'generate']"> - <xsl:variable name="input"> +<xsl:template name="augment_transformation"> + <xsl:param name="base"/> + <xsl:param name="transformation"/> + + <transformation mode="{$transformation/@mode}"> <xsl:choose> - <xsl:when test="input/@mode = 'embedded'"> - <xsl:copy-of select="input/node()"/> + <xsl:when test="$transformation/@mode = 'file'"> + <xsl:value-of select="$file/@base"/> + <xsl:text>/</xsl:text> + <xsl:value-of select="$transformation/text()"/> </xsl:when> - <xsl:when test="input/@mode = 'file'"> - <xsl:copy-of select="InputXSLT:read-file(input/text())/self::file/node()"/> + <xsl:when test="$transformation/@mode = 'chain'"> + <xsl:for-each select="$transformation/link"> + <link> + <xsl:value-of select="$base"/> + <xsl:text>/</xsl:text> + <xsl:value-of select="text()"/> + </link> + </xsl:for-each> </xsl:when> + <xsl:otherwise> + <xsl:copy-of select="$transformation/node()"/> + </xsl:otherwise> </xsl:choose> - </xsl:variable> + </transformation> +</xsl:template> + +<xsl:template name="read_module"> + <xsl:param name="path"/> + + <xsl:variable name="file" select="InputXSLT:read-file($path)/self::file"/> + + <xsl:choose> + <xsl:when test="$file/@result = 'success'"> + <xsl:choose> + <xsl:when test="name($file/node()) = 'transformation'"> + <xsl:call-template name="augment_transformation"> + <xsl:with-param name="base" select="$file/@base"/> + <xsl:with-param name="transformation" select="$file/node()"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:copy-of select="$file/node()"/> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:message terminate="yes"> + <xsl:text>Failed to resolve module "</xsl:text> + <xsl:value-of select="$path"/> + <xsl:text>"</xsl:text> + </xsl:message> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="resolve_module"> + <xsl:param name="input"/> + <xsl:param name="definition"/> <xsl:choose> - <xsl:when test="transformation/@mode = 'chain'"> + <xsl:when test="$definition/@mode = 'file'"> + <xsl:variable name="module"> + <xsl:call-template name="read_module"> + <xsl:with-param name="path" select="$definition/text()"/> + </xsl:call-template> + </xsl:variable> + + <xsl:call-template name="handle_generate"> + <xsl:with-param name="input" select="$input"/> + <xsl:with-param name="transformation" select="xalan:nodeset($module)/transformation"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:message terminate="yes"> + <xsl:text>Failed to resolve module definition mode "</xsl:text> + <xsl:value-of select="$definition/@mode"/> + <xsl:text>"</xsl:text> + </xsl:message> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="resolve_transformation"> + <xsl:param name="input"/> + <xsl:param name="transformation"/> + + <xsl:choose> + <xsl:when test="$transformation/@mode = 'chain'"> <xsl:variable name="chain"> - <xsl:for-each select="transformation/link"> + <xsl:for-each select="$transformation/link"> <xsl:sort select="position()" data-type="number" order="descending"/> <xsl:copy-of select="."/> @@ -79,13 +167,87 @@ <xsl:with-param name="tail" select="xalan:nodeset($chain)/link[position() > 1]"/> </xsl:call-template> </xsl:when> - <xsl:when test="transformation/@mode = 'file'"> + <xsl:when test="$transformation/@mode = 'file'"> <xsl:call-template name="generate"> <xsl:with-param name="input" select="$input"/> - <xsl:with-param name="transformation" select="transformation/text()"/> + <xsl:with-param name="transformation" select="$transformation/text()"/> </xsl:call-template> </xsl:when> + <xsl:otherwise> + <xsl:message terminate="yes"> + <xsl:text>Failed to resolve transformation mode "</xsl:text> + <xsl:value-of select="$transformation/@mode"/> + <xsl:text>"</xsl:text> + </xsl:message> + </xsl:otherwise> </xsl:choose> </xsl:template> +<xsl:template name="resolve_input"> + <xsl:param name="input"/> + + <xsl:choose> + <xsl:when test="$input/@mode = 'embedded'"> + <xsl:copy-of select="$input/node()"/> + </xsl:when> + <xsl:when test="$input/@mode = 'file'"> + <xsl:copy-of select="InputXSLT:read-file($input/text())/self::file/node()"/> + </xsl:when> + <xsl:otherwise> + <xsl:message terminate="yes"> + <xsl:text>Failed to resolve input mode "</xsl:text> + <xsl:value-of select="$input/@mode"/> + <xsl:text>"</xsl:text> + </xsl:message> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="handle_generate"> + <xsl:param name="input"/> + <xsl:param name="transformation"/> + + <xsl:call-template name="resolve_transformation"> + <xsl:with-param name="input"> + <xsl:call-template name="resolve_input"> + <xsl:with-param name="input" select="$input"/> + </xsl:call-template> + </xsl:with-param> + <xsl:with-param name="transformation" select="$transformation"/> + </xsl:call-template> +</xsl:template> + +<xsl:template name="handle_module"> + <xsl:param name="input"/> + <xsl:param name="definition"/> + + <xsl:call-template name="resolve_module"> + <xsl:with-param name="input" select="$input"/> + <xsl:with-param name="definition" select="$definition"/> + </xsl:call-template> +</xsl:template> + +<xsl:template match="task[@type = 'generate']"> + <xsl:call-template name="handle_generate"> + <xsl:with-param name="input" select="input"/> + <xsl:with-param name="transformation" select="transformation"/> + </xsl:call-template> +</xsl:template> + +<xsl:template match="task[@type = 'module']"> + <xsl:call-template name="handle_module"> + <xsl:with-param name="input" select="input"/> + <xsl:with-param name="definition" select="definition"/> + </xsl:call-template> +</xsl:template> + +<xsl:template match="task"> + <xsl:message terminate="yes"> + <xsl:text>Failed to handle task type "</xsl:text> + <xsl:value-of select="@type"/> + <xsl:text>"</xsl:text> + </xsl:message> +</xsl:template> +<xsl:template match="text()|@*"/> + </xsl:stylesheet> |