aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-07-22 21:04:31 +0200
committerAdrian Kummerlaender2014-07-22 21:04:31 +0200
commita1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8 (patch)
treecc20a9eb9d0869dc17f8c27b2a9ec41ae11b60ad
parent9e26e5d35fcfc7c052295efff072577f9fb0d4f4 (diff)
downloadblog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.tar
blog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.tar.gz
blog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.tar.bz2
blog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.tar.lz
blog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.tar.xz
blog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.tar.zst
blog.kummerlaender.eu-a1df0a45a4fafa9142b0b6b7bc5a633dce0c6ad8.zip
Restructured generation logic into separate templates
* root template iterates through the levels and calls the "process" template for each stylesheet * the "process" template handles metadata extraction and main datasource resolution ** calls "compile" template for generation preparation * the "compile" template resolves the support datasources, merges the final datasource and resolves the target path using additional helper templates * actual generation of the result is preformed by the "generate" template as before
-rw-r--r--generate.xsl206
-rw-r--r--source/03_result/page.xsl2
2 files changed, 114 insertions, 94 deletions
diff --git a/generate.xsl b/generate.xsl
index f256c9d..eace77a 100644
--- a/generate.xsl
+++ b/generate.xsl
@@ -15,7 +15,7 @@
indent="yes"
/>
-<xsl:template name="generator">
+<xsl:template name="generate">
<xsl:param name="input"/>
<xsl:param name="transformation"/>
<xsl:param name="target"/>
@@ -27,51 +27,126 @@
)/self::generation"/>
</xsl:template>
-<xsl:template name="compiler">
- <xsl:param name="input"/>
+<xsl:template name="merge_datasource">
+ <xsl:param name="main"/>
+ <xsl:param name="support"/>
+
+ <datasource>
+ <xsl:copy-of select="$main"/>
+ <xsl:copy-of select="$support"/>
+ </datasource>
+</xsl:template>
+
+<xsl:template name="resolve_datasource">
+ <xsl:param name="datasource"/>
+
+ <xsl:for-each select="$datasource">
+ <xsl:element name="{./@target}">
+ <xsl:choose>
+ <xsl:when test="./@mode = 'full'">
+ <xsl:copy-of select="InputXSLT:read-file(./@source)/self::file/*/*"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:element>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template name="resolve_target">
+ <xsl:param name="prefix"/>
+ <xsl:param name="target"/>
+ <xsl:param name="datasource"/>
+
+ <xsl:choose>
+ <xsl:when test="$target/@mode = 'plain'">
+ <xsl:value-of select="concat($prefix, '/', $target/@value)"/>
+ </xsl:when>
+ <xsl:when test="$target/@mode = 'xpath'">
+ <xsl:value-of select="concat($prefix, '/', dyn:evaluate($target/@value))"/>
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="compile">
+ <xsl:param name="main"/>
+ <xsl:param name="support"/>
<xsl:param name="transformation"/>
<xsl:param name="target_prefix"/>
<xsl:param name="target"/>
+ <xsl:variable name="datasource">
+ <xsl:call-template name="merge_datasource">
+ <xsl:with-param name="main" select="$main"/>
+ <xsl:with-param name="support">
+ <xsl:call-template name="resolve_datasource">
+ <xsl:with-param name="datasource" select="$support"/>
+ </xsl:call-template>
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+
<xsl:variable name="resolved_target">
- <xsl:choose>
- <xsl:when test="$target/@mode = 'plain'">
- <xsl:value-of select="$target/@value"/>
- </xsl:when>
- <xsl:when test="$target/@mode = 'xpath'">
- <xsl:value-of select="dyn:evaluate($target/@value)"/>
- </xsl:when>
- <xsl:otherwise>
-
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:call-template name="resolve_target">
+ <xsl:with-param name="prefix" select="$target_prefix"/>
+ <xsl:with-param name="target" select="$target"/>
+ <xsl:with-param name="datasource" select="$datasource"/>
+ </xsl:call-template>
</xsl:variable>
- <xsl:call-template name="generator">
- <xsl:with-param name="input" select="$input"/>
+ <xsl:call-template name="generate">
+ <xsl:with-param name="input" select="$datasource"/>
<xsl:with-param name="transformation" select="$transformation"/>
- <xsl:with-param name="target" select="concat($target_prefix, '/', $resolved_target)"/>
+ <xsl:with-param name="target" select="$resolved_target"/>
</xsl:call-template>
</xsl:template>
-<xsl:template name="datasource">
- <xsl:param name="main"/>
- <xsl:param name="support"/>
+<xsl:template name="process">
+ <xsl:param name="level"/>
+ <xsl:param name="file"/>
- <datasource>
- <xsl:copy-of select="$main"/>
- <xsl:for-each select="$support">
- <xsl:element name="{./@target}">
- <xsl:choose>
- <xsl:when test="./@mode = 'full'">
- <xsl:copy-of select="InputXSLT:read-file(./@source)/self::file/*/*"/>
- </xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:element>
- </xsl:for-each>
- </datasource>
+ <xsl:variable name="transformation" select="InputXSLT:read-file($file/full)/self::file/*"/>
+ <xsl:variable name="meta" select="$transformation/self::*[name() = 'xsl:stylesheet']/*[name() = 'xsl:variable' and @name = 'meta']"/>
+ <xsl:variable name="main_source" select="$meta/datasource[@type = 'main']"/>
+ <xsl:variable name="support_source" select="$meta/datasource[@type = 'support']"/>
+ <xsl:variable name="target_prefix" select="concat('target/', $level/name)"/>
+
+ <xsl:choose>
+ <xsl:when test="$main_source/@mode = 'full'">
+ <xsl:call-template name="compile">
+ <xsl:with-param name="main">
+ <xsl:element name="{$main_source/@target}">
+ <xsl:copy-of select="InputXSLT:read-file($main_source/@source)/self::file/*/*"/>
+ </xsl:element>
+ </xsl:with-param>
+ <xsl:with-param name="support" select="$support_source"/>
+ <xsl:with-param name="transformation" select="$transformation"/>
+ <xsl:with-param name="target_prefix" select="$target_prefix"/>
+ <xsl:with-param name="target" select="$meta/target"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$main_source/@mode = 'iterate'">
+ <xsl:for-each select="InputXSLT:read-file($main_source/@source)/self::file/*/entry">
+ <xsl:call-template name="compile">
+ <xsl:with-param name="main">
+ <xsl:element name="{$main_source/@target}">
+ <xsl:copy-of select="."/>
+ </xsl:element>
+ </xsl:with-param>
+ <xsl:with-param name="support" select="$support_source"/>
+ <xsl:with-param name="transformation" select="$transformation"/>
+ <xsl:with-param name="target_prefix" select="$target_prefix"/>
+ <xsl:with-param name="target" select="$meta/target"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="compile">
+ <xsl:with-param name="support" select="$support_source"/>
+ <xsl:with-param name="transformation" select="$transformation"/>
+ <xsl:with-param name="target_prefix" select="$target_prefix"/>
+ <xsl:with-param name="target" select="$meta/target"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template match="/">
@@ -79,65 +154,10 @@
<xsl:variable name="level" select="."/>
<xsl:for-each select="InputXSLT:read-directory(./full)/entry[./extension = '.xsl']">
- <xsl:variable name="transformation" select="InputXSLT:read-file(./full)/self::file/*"/>
- <xsl:variable name="meta" select="$transformation/self::*[name() = 'xsl:stylesheet']/*[name() = 'xsl:variable' and @name = 'meta']"/>
- <xsl:variable name="main_source" select="$meta/datasource[@type = 'main']"/>
- <xsl:variable name="support_source" select="$meta/datasource[@type = 'support']"/>
- <xsl:variable name="target_prefix" select="concat('target/', $level/name)"/>
- <xsl:variable name="target" select="$meta/target"/>
-
- <xsl:choose>
- <xsl:when test="$main_source/@mode = 'full'">
- <xsl:call-template name="compiler">
- <xsl:with-param name="input">
- <xsl:call-template name="datasource">
- <xsl:with-param name="main">
- <xsl:element name="{$main_source/@target}">
- <xsl:copy-of select="InputXSLT:read-file($main_source/@source)/self::file/*/*"/>
- </xsl:element>
- </xsl:with-param>
- <xsl:with-param name="support" select="$support_source"/>
- </xsl:call-template>
- </xsl:with-param>
- <xsl:with-param name="transformation" select="$transformation"/>
- <xsl:with-param name="target_prefix" select="$target_prefix"/>
- <xsl:with-param name="target" select="$target"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="$main_source/@mode = 'iterate'">
- <xsl:variable name="datasource" select="InputXSLT:read-file($main_source/@source)/self::file/*"/>
-
- <xsl:for-each select="$datasource/entry">
- <xsl:call-template name="compiler">
- <xsl:with-param name="input">
- <xsl:call-template name="datasource">
- <xsl:with-param name="main">
- <xsl:element name="{$main_source/@target}">
- <xsl:copy-of select="."/>
- </xsl:element>
- </xsl:with-param>
- <xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/>
- </xsl:call-template>
- </xsl:with-param>
- <xsl:with-param name="transformation" select="$transformation"/>
- <xsl:with-param name="target_prefix" select="$target_prefix"/>
- <xsl:with-param name="target" select="$target"/>
- </xsl:call-template>
- </xsl:for-each>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="compiler">
- <xsl:with-param name="input">
- <xsl:call-template name="datasource">
- <xsl:with-param name="support" select="$meta/datasource[@type = 'support']"/>
- </xsl:call-template>
- </xsl:with-param>
- <xsl:with-param name="transformation" select="$transformation"/>
- <xsl:with-param name="target_prefix" select="$target_prefix"/>
- <xsl:with-param name="target" select="$target"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
+ <xsl:call-template name="process">
+ <xsl:with-param name="level" select="$level"/>
+ <xsl:with-param name="file" select="."/>
+ </xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
diff --git a/source/03_result/page.xsl b/source/03_result/page.xsl
index e3839a7..fc8b3a5 100644
--- a/source/03_result/page.xsl
+++ b/source/03_result/page.xsl
@@ -19,7 +19,7 @@
<xsl:variable name="meta">
<datasource type="main" mode="iterate" source="target/02_data/pages.xml" target="page"/>
<datasource type="support" mode="full" source="source/00_content/meta.xml" target="meta"/>
- <target mode="xpath" value="concat('pages/', xalan:nodeset($input)/datasource/page/entry/@handle)"/>
+ <target mode="xpath" value="concat('pages/', xalan:nodeset($datasource)/datasource/page/entry/@handle)"/>
</xsl:variable>
<xsl:template name="title-text">