XSL path normalization to make all stupid validators happy

This commit is contained in:
Astro 2010-11-09 23:14:23 +01:00
parent 63a8d2c7cb
commit 60c0085f9f
2 changed files with 56 additions and 9 deletions

View File

@ -53,8 +53,16 @@
</xsl:template>
<xsl:template match="image">
<xsl:variable name="path">
<xsl:call-template name="normalize-path">
<xsl:with-param name="path">
<xsl:value-of select="string(.)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<img
src="{.}"
src="{$path}"
title="{@title}"
alt="{@title}"
class="{@class}"/>
@ -321,4 +329,37 @@
</xsl:choose>
</xsl:template>
<xsl:template name="normalize-path">
<xsl:param name="path"/>
<xsl:choose>
<xsl:when test="contains($path, '/')">
<xsl:variable name="dir1" select="substring-before($path, '/')"/>
<xsl:variable name="dir2" select="substring-after($path, '/')"/>
<xsl:choose>
<xsl:when test="starts-with($dir2, '../')">
<!-- recurse with xxx/../ removed -->
<xsl:call-template name="normalize-path">
<xsl:with-param name="path">
<xsl:value-of select="substring-after($dir2, '../')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- spit out and recurse with tail -->
<xsl:value-of select="$dir1"/><xsl:text>/</xsl:text><xsl:call-template name="normalize-path">
<xsl:with-param name="path">
<xsl:value-of select="$dir2"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- just a filename with no / -->
<xsl:value-of select="$path"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

View File

@ -276,14 +276,20 @@
<xsl:param name="itemposition"/>
<img>
<xsl:choose>
<xsl:when test="contains(., '://')">
<xsl:attribute name="src"><xsl:value-of select="."/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="src"><xsl:value-of select="concat($baseurl, 'images/news/', .)"/></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="src">
<xsl:call-template name="normalize-path">
<xsl:with-param name="path">
<xsl:choose>
<xsl:when test="contains(., '://')">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($baseurl, 'images/news/', .)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="@title"/></xsl:attribute>