<?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"
  exclude-result-prefixes="xsl date">

  <xsl:output method="xml"
              version="1.0"
              encoding="utf-8"
              doctype-system="http://www.c3d2.de/dtd/c3d2web.dtd"
              indent="yes"/>

  <xsl:template match="/calendar">
    <page>
      <calendar-summary>
        <!-- Events aus events.xml ziehen -->
        <xsl:apply-templates select="event"/>

        <!-- Events aus den News ziehen -->
        <xsl:for-each select="document('../news.xml')/page/news/newsfile">
          <xsl:message>newsfile: <xsl:value-of select="."/></xsl:message>
          <xsl:apply-templates select="document(concat('../', .))/item/event"/>
        </xsl:for-each>
      </calendar-summary>
    </page>
  </xsl:template>

  <xsl:template match="event">
    <event>
      <title>
        <xsl:choose>
          <xsl:when test="@title"><xsl:value-of select="@title"/></xsl:when>
          <xsl:when test="../@title"><xsl:value-of select="../@title"/></xsl:when>
          <xsl:otherwise>
            <xsl:message terminate="yes">Event with no title!</xsl:message>
          </xsl:otherwise>
        </xsl:choose>
      </title>
      <date><xsl:value-of select="start"/></date>
      <location><xsl:value-of select="location"/></location>
      <!-- TODO: Link -->
    </event>
  </xsl:template>

</xsl:stylesheet>
