c3d2-web/transformation/page2html/include/helpers.xsl

72 lines
2.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:crypto="http://exslt.org/crypto"
exclude-result-prefixes="xsl date crypto">
<!-- TODO: Check if this template can be safely removed.
<xsl:template name="make-href">
<xsl:param name="href"/>
<xsl:choose>
<xsl:when test="$href">
<xsl:value-of select="$href"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</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:template name="make-flattr-link">
<xsl:param name="newsfile"/>
<xsl:if test="starts-with($newsfile, 'content/news/pentaradio24-') or
starts-with($newsfile, 'content/news/pentacast-') or
starts-with($newsfile, 'content/news/pentamusic-')">
<xsl:text>https://flattr.com/submit/auto?user_id=coloradio&amp;url=</xsl:text>
<xsl:value-of select="str:encode-uri(concat($baseurl, substring-before(substring-after($newsfile, 'content/'), '.xml'), '.html'), true())"/>
<xsl:text>&amp;title=</xsl:text>
<xsl:value-of select="str:encode-uri(document($newsfile)/item/@title, true())"/>
<xsl:text>&amp;description=</xsl:text>
<xsl:value-of select="str:encode-uri(document($newsfile)//p[1], true())"/>
<xsl:text>&amp;language=de&amp;tags=audio,c3d2,podcast&amp;category=audio</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>