diff options
Diffstat (limited to 'compile.xsl')
-rw-r--r-- | compile.xsl | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/compile.xsl b/compile.xsl new file mode 100644 index 0000000..656ee94 --- /dev/null +++ b/compile.xsl @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + <xsl:output method="text"/> + + <xsl:template match="/sitemap"> +# Makefile generato automaticamente via XSLT + +all: Makefile <xsl:for-each select=".//main|.//page" xml:space="preserve"><xsl:call-template name="abs"><xsl:with-param name="attr" select="'dest'"/></xsl:call-template> </xsl:for-each> + +Makefile: sitemap.xml compile.xsl + xsltproc -o Makefile compile.xsl sitemap.xml + +<xsl:for-each select="type"> +<xsl:apply-templates select="."/> +</xsl:for-each> + +<xsl:for-each select=".//main|.//page" xml:space="preserve"> +<xsl:apply-templates select="."/> +</xsl:for-each> +</xsl:template> + + <xsl:template match="main|page"> +<xsl:call-template name="abs"><xsl:with-param name="attr" select="'dest'"/></xsl:call-template> : _ACTIVE_ELEM='<xsl:call-template name="xpathfor"/>' +<xsl:call-template name="abs"><xsl:with-param name="attr" select="'dest'"/></xsl:call-template> : <xsl:call-template name="abs"><xsl:with-param name="attr" select="'src'"/></xsl:call-template> $(_<xsl:value-of select="@type"/>_PREQ) + $(_<xsl:value-of select="@type"/>_CMD) +</xsl:template> + +<!-- chiamato con ctx-node un elemento main|page, restituisce un espressione XPath che lo individua --> + <xsl:template name="xpathfor"> + <xsl:param name="cnode" select="."/> + <xsl:choose> + <xsl:when test="$cnode = /sitemap">/sitemap</xsl:when> + <xsl:otherwise><xsl:call-template name="xpathfor"><xsl:with-param name="cnode" select="$cnode/parent::node()"/></xsl:call-template>/<xsl:value-of select="name($cnode)"/>[@name="<xsl:value-of select="$cnode/@name"/>"]</xsl:otherwise> + </xsl:choose> + </xsl:template> + +<!-- chiamato con ctx-node un elemento main|page, deve restituire il percorso completo della pagina relativo alla sitemap, ottenuto concatenando gli attributi @src o @dest degli elementi padre --> + <xsl:template name="abs"> + <xsl:param name="cnode" select="."/> + <xsl:param name="attr"/> + <xsl:choose> + <xsl:when test="$cnode = /sitemap"> + <xsl:value-of select="$cnode/attribute::*[name()=$attr]"/> + </xsl:when> + <xsl:otherwise> + <xsl:variable name="prev"><xsl:call-template name="abs"><xsl:with-param name="cnode" select="$cnode/parent::node()"/><xsl:with-param name="attr" select="$attr"/></xsl:call-template></xsl:variable> + <xsl:choose> + <xsl:when test="$cnode/attribute::*[name()=$attr]"> + <xsl:value-of select="$prev"/>/<xsl:value-of select="$cnode/attribute::*[name()=$attr]"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$prev"/> + </xsl:otherwise> + </xsl:choose> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + +<!-- chiamato con ctx-node pari ad un elemento type/xslt, deve ritornare il percorso completo della sitemap relativo allo stylesheet --> + <xsl:template name="rel"> + <xsl:param name="href" select="@href"/> + <xsl:choose> + <xsl:when test="contains($href,'/')">../<xsl:call-template name="rel"><xsl:with-param name="href" select="substring-after($href,'/')"/></xsl:call-template></xsl:when> + <xsl:otherwise>sitemap.xml</xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template name="params"> + <xsl:for-each select="param" xml:space="preserve">--stringparam <xsl:value-of select="@name"/> <xsl:value-of select="text()"/> </xsl:for-each> + <xsl:text xml:space="preserve">--stringparam sitemapuri </xsl:text><xsl:call-template name="rel"/> + <xsl:text xml:space="preserve"> --stringparam active $(_ACTIVE_ELEM)</xsl:text> <!-- questo sarĂ un'espressione XPath che indica il nodo relativo alla pagina che stiamo elaborando. xsltproc interpreta i parametri con ctx-node pari alla radice del file xml da trasformare --> + </xsl:template> + + <xsl:template match="type[child::xslt]" xml:space="preserve"> +_<xsl:value-of select="@name"/>_PREQ = <xsl:for-each select="xslt" xml:space="preserve"><xsl:value-of select="@href"/> </xsl:for-each> +_<xsl:value-of select="@name"/>_CMD = mkdir -p `dirname $@`;<xsl:for-each select="xslt"><xsl:choose><xsl:when test="position()=1">xsltproc <xsl:call-template name="params"/> <xsl:value-of select="@href"/> $<</xsl:when><xsl:otherwise>|xsltproc <xsl:call-template name="params"/> <xsl:value-of select="@href"/> -</xsl:otherwise></xsl:choose></xsl:for-each> > $@ + +</xsl:template> + + <xsl:template match="type[child::command]"> +_<xsl:value-of select="@name"/>_PREQ = +define _<xsl:value-of select="@name"/>_CMD +<xsl:for-each select="command"> +<xsl:value-of select="."/> +</xsl:for-each> +endef +</xsl:template> + +</xsl:stylesheet> |