diff options
-rw-r--r-- | generate.xsl | 206 | ||||
-rw-r--r-- | source/03_result/page.xsl | 2 |
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"> |