diff options
Replaced function-like data resolution with template applications
* e.g. article and tag support data is now fetched through direct _XPath_ template applications
** this required the introduction of a special `resolve` mode to prevent interaction between support and main content resolution
** in most cases arguments had to be wrapped inside helper constants to enable selection of e.g. article support data via the `@handle` attribute using the current elements `@handle` attribute
* analogously to the recent changes in _StaticXSLT_ this commit aims to improve the XSLT code style used in generating this static website
Diffstat (limited to 'source/02_meta')
-rw-r--r-- | source/02_meta/articles.xsl | 34 | ||||
-rw-r--r-- | source/02_meta/categories.xsl | 20 | ||||
-rw-r--r-- | source/02_meta/tags.xsl | 28 |
3 files changed, 35 insertions, 47 deletions
diff --git a/source/02_meta/articles.xsl b/source/02_meta/articles.xsl index 1a8b8fa..f91ff1e 100644 --- a/source/02_meta/articles.xsl +++ b/source/02_meta/articles.xsl @@ -11,31 +11,27 @@ <target mode="plain" value="articles.xml"/> </xsl:variable> -<xsl:key name="years" match="datasource/articles/entry/date/year/text()" use="." /> +<xsl:key name="years" match="datasource/articles/entry/date/year/text()" use="."/> + +<xsl:template match="articles/entry" mode="resolve"> + <article handle="{@handle}"> + <title> + <xsl:value-of select="title"/> + </title> + <date> + <xsl:value-of select="date/full"/> + </date> + </article> +</xsl:template> <xsl:template match="articles"> <xsl:for-each select="entry/date/year/text()[generate-id() = generate-id(key('years',.)[1])]"> + <xsl:variable name="year" select="."/> + <entry handle="{.}"> - <xsl:call-template name="get_articles"> - <xsl:with-param name="year" select="."/> - </xsl:call-template> + <xsl:apply-templates select="$root/articles/entry[./date/year = $year]" mode="resolve"/> </entry> </xsl:for-each> </xsl:template> -<xsl:template name="get_articles"> - <xsl:param name="year"/> - - <xsl:for-each select="/datasource/articles/entry[date/year = $year]"> - <article handle="{@handle}"> - <title> - <xsl:value-of select="title"/> - </title> - <date> - <xsl:value-of select="date/full"/> - </date> - </article> - </xsl:for-each> -</xsl:template> - </xsl:stylesheet> diff --git a/source/02_meta/categories.xsl b/source/02_meta/categories.xsl index 1a06aa1..ea8593b 100644 --- a/source/02_meta/categories.xsl +++ b/source/02_meta/categories.xsl @@ -15,17 +15,13 @@ <target mode="plain" value="categories.xml"/> </xsl:variable> -<xsl:template name="get_page_data"> - <xsl:param name="handle"/> - - <xsl:variable name="page" select="$root/pages/entry[@handle = $handle]"/> - - <page handle="{$handle}"> +<xsl:template match="pages/entry" mode="resolve"> + <page handle="{@handle}"> <title> - <xsl:value-of select="$page/title"/> + <xsl:value-of select="title"/> </title> - <digest size="{string-length($page/content/p[1])}"> - <xsl:copy-of select="$page/content/p[1]/node()"/> + <digest size="{string-length(content/p[1])}"> + <xsl:copy-of select="content/p[1]/node()"/> </digest> </page> </xsl:template> @@ -37,9 +33,9 @@ </xsl:template> <xsl:template match="files/directory[@name = 'pages']/*/file[@extension = '.md']"> - <xsl:call-template name="get_page_data"> - <xsl:with-param name="handle" select="@name"/> - </xsl:call-template> + <xsl:variable name="handle" select="@name"/> + + <xsl:apply-templates select="$root/pages/entry[@handle = $handle]" mode="resolve"/> </xsl:template> </xsl:stylesheet> diff --git a/source/02_meta/tags.xsl b/source/02_meta/tags.xsl index 20b1f10..3c95932 100644 --- a/source/02_meta/tags.xsl +++ b/source/02_meta/tags.xsl @@ -12,17 +12,15 @@ <target mode="plain" value="tags.xml"/> </xsl:variable> -<xsl:template name="get_article_data"> - <xsl:param name="handle"/> - - <xsl:variable name="article" select="$root/articles/entry[@handle = $handle]/*[self::title | self::date]"/> - - <title> - <xsl:value-of select="$article/self::title"/> - </title> - <date> - <xsl:value-of select="$article/self::date/full"/> - </date> +<xsl:template match="articles/entry" mode="resolve"> + <article handle="{@handle}"> + <title> + <xsl:value-of select="title"/> + </title> + <date> + <xsl:value-of select="date/full"/> + </date> + </article> </xsl:template> <xsl:template match="tags/entry"> @@ -32,11 +30,9 @@ </xsl:template> <xsl:template match="tags/*/article"> - <article handle="{@handle}"> - <xsl:call-template name="get_article_data"> - <xsl:with-param name="handle" select="@handle"/> - </xsl:call-template> - </article> + <xsl:variable name="handle" select="@handle"/> + + <xsl:apply-templates select="$root/articles/entry[@handle = $handle]" mode="resolve"/> </xsl:template> </xsl:stylesheet> |