c3d2-web/transformation/news2page/include/item.xsl

332 lines
11 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
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">
<xsl:template match="/item">
<page title="@title">
<xsl:apply-templates />
</page>
</xsl:template>
<xsl:template match="item/event">
<dl>
<xsl:apply-templates/>
</dl>
</xsl:template>
<xsl:template match="item/event/start">
<xsl:variable name="start" select="."/>
<xsl:variable name="end" select="../end"/>
<dt>Datum</dt>
<dd>
<abbr class="dtstart">
<xsl:attribute name="title">
<xsl:call-template name="date-to-hevent">
<xsl:with-param name="date" select="$start"/>
</xsl:call-template>
</xsl:attribute>
<xsl:call-template name="get-datestring">
<xsl:with-param name="date" select="$start"/>
</xsl:call-template>
</abbr>
<xsl:if test="$end">
bis
<abbr class="dtend">
<xsl:attribute name="title">
<xsl:call-template name="date-to-hevent">
<xsl:with-param name="date" select="$end"/>
</xsl:call-template>
</xsl:attribute>
<xsl:choose>
<!-- Ends on same day it starts? -->
<xsl:when test="date:date($start) = date:date($end)">
<xsl:call-template name="get-timestring">
<xsl:with-param name="date" select="$end"/>
</xsl:call-template>
</xsl:when>
<!-- Event spans days -->
<xsl:otherwise>
<xsl:call-template name="get-datestring">
<xsl:with-param name="date" select="$end"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</abbr>
</xsl:if>
</dd>
</xsl:template>
<xsl:template match="item/event/end">
<!-- Output already for item/event/start above -->
</xsl:template>
<xsl:template match="item/event/location">
<dt>Ort</dt>
<dd class="location"><xsl:apply-templates/></dd>
</xsl:template>
<!--
<xsl:template match="item/image[1]">
<xsl:variable name="path">
<xsl:call-template name="normalize-path">
<xsl:with-param name="path">
<xsl:value-of select="concat($baseurl, 'images/news/', .)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<img
src="{$path}"
title="{@title}"
alt="{@title}"
class="{@class}"/>
</xsl:template>
<xsl:template match="item/image">
<xsl:param name="itemposition"/>
<img>
<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>
News-Items haben ihre Bilder abwechselnd rechts und links...
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$itemposition mod 2 = 1">
<xsl:text>left</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>right</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</img>
</xsl:template>
-->
<!-- Resources/alternatives in HTML -->
<xsl:template match="resource">
<xsl:choose>
<xsl:when test="not(starts-with(@type, 'video/')) or count(resource[not(starts-with(@type, 'video/'))]) &gt; 0">
<!-- Is not only video/* -->
<ul>
<xsl:call-template name="resource-item"/>
<xsl:apply-templates mode="resource"/>
</ul>
</xsl:when>
<xsl:otherwise>
<!-- Video only -->
<xsl:call-template name="video-resource"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="resource/alternative" mode="resource">
<xsl:call-template name="resource-item">
<xsl:with-param name="title">
<xsl:choose>
<xsl:when test="@title"><xsl:value-of select="@title"/></xsl:when>
<xsl:otherwise><xsl:value-of select="../@title"/></xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="resource-item">
<xsl:param name="title" select="@title"/>
<!-- @class = "resource" | "alternative" -->
<li class="{name(.)}">
<!-- HTML5 dataset hints for play-resources.js poster -->
<xsl:if test="@poster">
<xsl:attribute name="data-poster">
<xsl:value-of select="@poster"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@preview">
<xsl:attribute name="data-preview">
<xsl:value-of select="@preview"/>
</xsl:attribute>
</xsl:if>
<!-- MIME type hinting works even in the browser -->
<a href="{@url}" type="{@type}" class="mime" rel="enclosure">
<xsl:choose>
<xsl:when test="string-length(string($title))"><xsl:value-of select="$title"/></xsl:when>
<xsl:otherwise><xsl:value-of select="@url"/></xsl:otherwise>
</xsl:choose>
</a>
(<xsl:call-template name="mime-for-human">
<xsl:with-param name="mime" select="@type"/>
</xsl:call-template>, <xsl:call-template name="format-filesize">
<xsl:with-param name="value" select="@size"/>
</xsl:call-template>)
</li>
</xsl:template>
<xsl:template name="video-resource">
<section class="video-resource">
<h4>
<xsl:choose>
<xsl:when test="@details-link">
<a href="{@details-link}">
<xsl:value-of select="@title"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@title"/>
</xsl:otherwise>
</xsl:choose>
</h4>
<ul>
<xsl:call-template name="video-resource-item"/>
<xsl:apply-templates mode="video-resource"/>
<xsl:if test="@feedback-link">
<li class="feedback"><a href="{@feedback-link}">Feedback</a></li>
</xsl:if>
</ul>
</section>
</xsl:template>
<xsl:template match="resource/alternative" mode="video-resource">
<xsl:call-template name="video-resource-item">
<xsl:with-param name="title">
<xsl:choose>
<xsl:when test="@title"><xsl:value-of select="@title"/></xsl:when>
<xsl:otherwise><xsl:value-of select="../@title"/></xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="video-resource-item">
<li class="{name(.)}">
<!-- HTML5 dataset hints for play-resources.js poster -->
<xsl:if test="@poster">
<xsl:attribute name="data-poster">
<xsl:value-of select="@poster"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@preview">
<xsl:attribute name="data-preview">
<xsl:value-of select="@preview"/>
</xsl:attribute>
</xsl:if>
<!-- MIME type hinting works even in the browser -->
<a href="{@url}" type="{@type}" class="mime" rel="enclosure">
<xsl:call-template name="mime-for-human-short">
<xsl:with-param name="mime" select="@type"/>
</xsl:call-template>
</a>
<span class="size">
<xsl:call-template name="format-filesize">
<xsl:with-param name="value" select="@size"/>
</xsl:call-template>
</span>
</li>
</xsl:template>
<xsl:template name="format-filesize">
<xsl:param name="value"/>
<xsl:choose>
<xsl:when test="$value &gt; 1024 * 1024 * 1024">
<xsl:value-of select="format-number($value div (1024 * 1024 * 1024), '0.0')"/>
<xsl:text> GB</xsl:text>
</xsl:when>
<xsl:when test="$value &gt; 1024 * 1024">
<xsl:value-of select="format-number($value div (1024 * 1024), '0.0')"/>
<xsl:text> MB</xsl:text>
</xsl:when>
<xsl:when test="$value &gt; 1024">
<xsl:value-of select="format-number($value div (1024), '0.0')"/>
<xsl:text> KB</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
<xsl:text> Bytes</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="mime-for-human">
<xsl:param name="mime"/>
<xsl:choose>
<xsl:when test="$mime = 'application/ogg'">Ogg Vorbis</xsl:when>
<xsl:when test="$mime = 'audio/ogg'">Ogg Vorbis</xsl:when>
<xsl:when test="$mime = 'audio/mpeg'">MPEG-Audio</xsl:when>
<xsl:when test="$mime = 'application/octet-stream'">Binärdatei</xsl:when>
<xsl:when test="$mime = 'application/xhtml+xml'">XHTML-Dokument</xsl:when>
<xsl:when test="$mime = 'text/html'">HTML-Dokument</xsl:when>
<xsl:when test="$mime = 'text/plain'">Text-Dokument</xsl:when>
<xsl:when test="$mime = 'application/pdf'">Portable Document Format</xsl:when>
<xsl:when test="$mime = 'image/svg+xml'">Scalable Vector Graphics</xsl:when>
<xsl:when test="$mime = 'image/gif'">GIF-Bild</xsl:when>
<xsl:when test="$mime = 'image/jpeg'">JPEG-Bild</xsl:when>
<xsl:when test="$mime = 'image/png'">PNG-Bild</xsl:when>
<xsl:when test="$mime = 'video/mpeg'">MPEG-Video</xsl:when>
<xsl:when test="$mime = 'video/mp4'">MP4-Video</xsl:when>
<xsl:when test="$mime = 'video/quicktime'">QuickTime-Video</xsl:when>
<xsl:when test="$mime = 'video/x-ms-wmv'">Windows Media-Video</xsl:when>
<xsl:when test="$mime = 'video/x-msvideo'">Video for Windows</xsl:when>
<xsl:when test="$mime = 'video/avi'">Audio Video Interleave</xsl:when>
<xsl:when test="$mime = 'video/ogg'">Ogg Media Video</xsl:when>
<xsl:when test="$mime = 'video/x-matroska'">Matroska Video</xsl:when>
<xsl:when test="$mime = 'video/x-m4v'">iTunes Video File</xsl:when>
<xsl:when test="$mime = 'video/webm'">WebM Video</xsl:when>
<xsl:when test="$mime = 'video/x-flv'">Flash Video</xsl:when>
<xsl:when test="$mime = 'application/x-gtar'">Komprimierter Tarball</xsl:when>
<xsl:when test="$mime = 'application/x-tar'">Tarball</xsl:when>
<xsl:when test="$mime = 'application/x-bittorrent'">BitTorrent-Metainformationen</xsl:when>
<xsl:when test="$mime = 'application/zip'">ZIP-Archiv</xsl:when>
<xsl:when test="$mime = 'multipart/x-zip'">ZIP-Archiv</xsl:when>
<xsl:when test="$mime = 'audio/opus'">Opus</xsl:when>
<xsl:otherwise>Datei</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="mime-for-human-short">
<xsl:param name="mime"/>
<xsl:choose>
<xsl:when test="@type='audio/mpeg'">MP3</xsl:when>
<xsl:when test="@type='video/mp4'">MP4</xsl:when>
<xsl:when test="@type='video/webm'">WebM</xsl:when>
<xsl:when test="@type='video/ogg'">Ogg</xsl:when>
<xsl:when test="@type='video/avi'">AVI</xsl:when>
<xsl:when test="@type='video/x-flv'">FLV</xsl:when>
<xsl:when test="@type='application/x-bittorrent'">BitTorrent</xsl:when>
<xsl:otherwise><xsl:value-of select="@type"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>