aboutsummaryrefslogtreecommitdiff
path: root/xsl/resolver.xsl
diff options
context:
space:
mode:
Diffstat (limited to 'xsl/resolver.xsl')
-rw-r--r--xsl/resolver.xsl122
1 files changed, 122 insertions, 0 deletions
diff --git a/xsl/resolver.xsl b/xsl/resolver.xsl
new file mode 100644
index 0000000..87dc543
--- /dev/null
+++ b/xsl/resolver.xsl
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:dyn="http://exslt.org/dynamic"
+ extension-element-prefixes="dyn"
+>
+ <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system="http://www.w3.org/TR/html40/strict.dtd" indent="yes"/>
+
+ <xsl:include href="identity.xsl"/>
+
+ <xsl:param name="sitemapuri"/>
+ <xsl:variable name="map" select="document($sitemapuri,document(''))"/>
+ <xsl:param name="active"/>
+ <xsl:variable name="activenode" select="dyn:evaluate(concat('$map',$active))"/>
+
+ <xsl:variable name="lang" select="/html/@xml_lang"/>
+
+ <!-- bisogna fare così, perché è un errore aggiungere attributi dopo i nodi figli, quindi bisogna forzare l'ordine. -->
+ <xsl:template match="*[@href|@src]">
+ <xsl:copy>
+ <xsl:apply-templates select="@*"/>
+ <xsl:apply-templates select="*|text()"/>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="@href|@src">
+
+ <xsl:attribute name="{name()}">
+
+ <xsl:choose>
+ <xsl:when test="$lang and starts-with(string(),'resolve:')">
+ <xsl:variable name="sub" select="substring-after(string(),':')"/>
+ <xsl:choose>
+ <xsl:when test="contains($sub,':')">
+ <xsl:call-template name="resolve">
+ <xsl:with-param name="ref"><xsl:value-of select="concat('resolve:',substring-after($sub,':'))"/></xsl:with-param>
+ <xsl:with-param name="nav" select="$map/sitemap/section[@name=substring-before($sub,':')]"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="resolve">
+ <xsl:with-param name="ref"><xsl:value-of select="."/></xsl:with-param>
+ <xsl:with-param name="nav" select="$map/sitemap/section[@name=$lang]"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="resolve">
+ <xsl:with-param name="ref"><xsl:value-of select="."/></xsl:with-param>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:attribute>
+ </xsl:template>
+
+ <xsl:template name="getpath">
+ <xsl:param name="dest"/>
+ <xsl:choose>
+ <xsl:when test="count($dest|$map/sitemap)=1">
+ <xsl:value-of select="$dest/@baseURL"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="getpath"><xsl:with-param name="dest" select="$dest/parent::*"/></xsl:call-template><xsl:if test="$dest/@dest"><xsl:value-of select="concat('/',$dest/@dest)"/></xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="resolve">
+ <xsl:param name="ref"/>
+ <xsl:param name="nav" select="$map/sitemap"/>
+ <xsl:choose>
+ <xsl:when test="starts-with($ref,'resolve:')">
+ <xsl:variable name="rif" select="substring-after($ref,':')"/>
+ <xsl:choose>
+ <xsl:when test="contains($rif,'#')">
+ <xsl:variable name="refname" select="substring-before($rif,'#')"/>
+ <xsl:variable name="fragment" select="substring-after($ref,'#')"/>
+ <xsl:choose>
+ <xsl:when test="$nav//*[@name=$refname]">
+ <xsl:call-template name="getpath">
+ <xsl:with-param name="dest" select="$nav//*[@name=$refname]"/>
+ </xsl:call-template>
+ <xsl:value-of select="concat('#',$fragment)"/>
+ </xsl:when>
+ <xsl:when test="$map/sitemap//*[@name=$refname]">
+ <xsl:call-template name="getpath">
+ <xsl:with-param name="dest" select="$map/sitemap//*[@name=$refname][1]"/>
+ </xsl:call-template>
+ <xsl:value-of select="concat('#',$fragment)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>WRONG REF:</xsl:text><xsl:value-of select="$ref"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:choose>
+ <xsl:when test="$nav//*[@name=$rif]">
+ <xsl:call-template name="getpath">
+ <xsl:with-param name="dest" select="$nav//*[@name=$rif]"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$map/sitemap//*[@name=$rif]">
+ <xsl:call-template name="getpath">
+ <xsl:with-param name="dest" select="$map/sitemap//*[@name=$rif][1]"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>WRONG REF:</xsl:text><xsl:value-of select="$ref"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$ref"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+</xsl:stylesheet>