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

167 lines
5.1 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">
<xsl:output method="xml"
version="1.0"
encoding="utf-8"
indent="yes"/>
<xsl:template match="news">
<page title="@title" id="@id">
<xsl:attribute name="title">
<xsl:value-of select="@title" />
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:apply-templates select="*" />
</page>
</xsl:template>
<xsl:template name="item-meta">
<small class="news_author">
<xsl:value-of select="@author"/>
</small>
<small class="news_date">
@
<time datetime="{@date}" pubdate="pubdate">
<xsl:call-template name="get-datestring">
<xsl:with-param name="date" select="@date" />
</xsl:call-template>
</time>
</small>
</xsl:template>
<xsl:template match="item-summary">
<xsl:variable name="list" select="@src" />
<xsl:variable name="dir" select="@dir" />
<xsl:variable name="display" select="@display" />
<xsl:variable name="count" select="@count" />
<!--
# Iterate over all files listed in the file under $src.
-->
<xsl:for-each select="document($list)/newsfiles/file">
<xsl:sort select="date:seconds(document(concat($dir , .))/item/@date)" data-type="number" order="descending" />
<xsl:variable name="itemfile" select="."/>
<xsl:if test="position() &lt;= number($count)">
<xsl:for-each select="document(concat($dir, $itemfile))/item">
<div>
<h3 class="summary">
<a href="{substring-before($itemfile, '.xml')}.html" class="url">
<xsl:value-of select="@title"/>
</a>
</h3>
<xsl:choose>
<xsl:when test="$display = 'news'">
<xsl:call-template name="item-meta"/>
</xsl:when>
<xsl:when test="$display = 'resources-only'">
<xsl:apply-templates select=".//resource"/>
</xsl:when>
<xsl:when test="($display = 'event') and event">
<ul class="details_event">
<li>
<abbr class="dtstart">
<xsl:attribute name="title">
<xsl:call-template name="date-to-hevent">
<xsl:with-param name="date" select="event/start"/>
</xsl:call-template>
</xsl:attribute>
<xsl:call-template name="get-datestring">
<xsl:with-param name="date" select="event/start"/>
</xsl:call-template>
</abbr>
</li>
<li class="location">
<xsl:value-of select="event/location"/>
</li>
</ul>
</xsl:when>
</xsl:choose>
</div>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="item-list">
<xsl:variable name="list" select="@src" />
<xsl:variable name="dir" select="@dir" />
<xsl:variable name="display" select="@display" />
<xsl:variable name="count" select="@count" />
<xsl:for-each select="document($list)/newsfiles/file">
<xsl:sort select="date:seconds(document(concat($dir, .))/item/@date)" data-type="number" order="descending" />
<xsl:if test="position() &lt;= number($count)">
<xsl:variable name="newsfile"><xsl:value-of select="."/></xsl:variable>
<xsl:variable name="itemposition" select="position()"/>
<xsl:for-each select="document(concat($dir, $newsfile))/item">
<article><div>
<xsl:if test="event">
<xsl:attribute name="class">vevent</xsl:attribute>
</xsl:if>
<header>
<h3 class="news summary">
<a href="{substring-before($newsfile, '.xml')}.html" class="url">
<xsl:value-of select="@title"/>
</a>
</h3>
<xsl:call-template name="item-meta"/>
</header>
<div class="news">
<xsl:apply-templates select="*[name() != 'addendum']">
<xsl:with-param name="itemposition" select="$itemposition"/>
</xsl:apply-templates>
<xsl:if test="//addendum or //resource[@hide='yes']">
<footer><p class="more">
<a href="{substring-before($newsfile, '.xml')}.html">
Weiterlesen…
</a>
</p></footer>
</xsl:if>
</div>
<hr class="news"/>
</div></article>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!--
# Identity transformation for all elements
# not handled by the templates within this file.
# Taken from
# http://stackoverflow.com/questions/10454114/xslt-template-for-any-node-not-already-handled
-->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>