<!DOCTYPE xsl:stylesheet [
<!ENTITY   copy  "&#169;">
<!ENTITY   reg   "&#174;">
]>
<xsl:stylesheet
    version="1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>

<!--

  This transformation selects an entry from the sermons.xml
  database according to the value of $input-name and formats it
  as a sermon page.  Used by sermon.php.  The sermon text is
  included from the file sermons/$input-name.xml

-->

<xsl:output
    method="xml"
    omit-xml-declaration="yes"
    encoding="utf-8"
    indent="no"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
/>

<!-- Main template -->
<xsl:template match="sermon">

  <html lang="en">

  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="sermon_style_basic.css" type="text/css" />
    <style type="text/css">
    @import url(sermon_style_extra.css);
    </style>

    <title>Ben's sermon: <xsl:value-of select="info/title"/></title>

    <script type="text/javascript">
    function popup(mylink, windowname)
    {
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href, windowname, 'width=400,height=120,scrollbars=yes');
    return false;
    }
    </script>

  </head>

  <body>

    <div class="links">
      <div class="left"><a href="./" title="List all my sermons">Sermon index</a></div>
      <div class="right"><a href="/" title="Go to my homepage">Home</a></div>
      <br class="both" />
    </div>

    <hr class="half"/>
    <div class="c1">
      <h1><xsl:value-of select="info/title"/></h1>
      <h2>
        <xsl:apply-templates select="info/mainref"/>
        <xsl:apply-templates select="info/extraref">
          <xsl:sort select="@num"/>
        </xsl:apply-templates>
      </h2>
      <h3><xsl:apply-templates select="info/date"/></h3>
      <h4><xsl:value-of select="info/place"/></h4>
      <h4><xsl:value-of select="info/occasion"/></h4>
    </div>
    <hr class="half" />

    <xsl:apply-templates select="body/*"/>

    <hr />
    <div class="links">
      <div class="copy-bpe">&copy; Copyright <xsl:number value="info/date/y"/>, <a href="/mail.php" title="Contact me">Ben Edgington</a>.</div>
      <div class="right"><a href="/" title="Go to my homepage">Home</a></div>
      <br class="both"/>
    </div>
    <hr />
    <div class="copyright">
      <p>Inline scripture quotes are taken from the Holy Bible, NEW INTERNATIONAL VERSION&reg;.  Copyright &copy;1973, 1978, 1984 International Bible Society. All rights reserved throughout the world. Used by permission of International Bible Society.</p>
      <p>Linked quotes are from the Holy Bible, English Standard Version&reg;.  Copyright &copy;2001 by Crossway Bibles, a division of Good News Publishers. Used by permission. All rights reserved. http://www.crosswaybibles.org</p>
    </div>
  </body>

  </html>

</xsl:template>


<!-- List the main Bible passages -->
<xsl:template match="mainref">
  <xsl:if test="not(position()=1)"><xsl:text>, </xsl:text></xsl:if>
  <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="extraref">
  <xsl:text>, </xsl:text>
  <xsl:value-of select="."/>
</xsl:template>


<!-- Format <ref/> elements as anchors -->
<xsl:template match="ref">
  <a>

    <!-- If we have a text attribute then format an anchor -->
    <xsl:if test="@text">
      <!-- <xsl:attribute name="name">REF<xsl:value-of select="generate-id(.)"/></xsl:attribute> -->
      <xsl:attribute name="name">REF_<xsl:value-of select="count(preceding::ref)"/></xsl:attribute>
    </xsl:if>

    <!-- Insert the reference text -->
    <span class="ref">

      <xsl:apply-templates/>

      <xsl:if test="@title">
        <a class="text" href="esv.php?passage={@title}" title="{@title}" onclick="return popup(this, 'Title')">ref</a>
      </xsl:if>
      <xsl:if test="@text">
        <a class="text" href="esv.php?passage={@text}" title="{@text}" onclick="return popup(this, 'Title')">ref</a>
      </xsl:if>

    </span>
  </a>

</xsl:template>


<!-- <interp/> are interpolations within references -->
<xsl:template match="interp">
  <span class="interp">
    <xsl:apply-templates/>
  </span>
</xsl:template>

<!-- transform <q/> for Netscape 4's benefit and IE!! -->
<xsl:template match="q">
  <span class="quote">
    &quot;<xsl:apply-templates/>&quot;
  </span>
</xsl:template>

<!-- Highlight embedded notes -->
<xsl:template match="note">
  <span class="note">
    <xsl:apply-templates/>
  </span>
</xsl:template>

<!--
     Recursive copy

     We avoid using xsl:copy here because that tends to inherit namespaces
     despite the use of exclude-result-prefixes above.  These two templates
     together seem to do a decent job of it.
-->
<xsl:template match="node()">
  <xsl:element name="{name()}">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*|text()|comment()|processing-instruction()">
    <xsl:copy/>
</xsl:template>

<xsl:template match="date">
  <xsl:number value="d"/>
  <xsl:text> </xsl:text>
  <xsl:choose>
  <xsl:when test="m=1">January</xsl:when>
  <xsl:when test="m=2">February</xsl:when>
  <xsl:when test="m=3">March</xsl:when>
  <xsl:when test="m=4">April</xsl:when>
  <xsl:when test="m=5">May</xsl:when>
  <xsl:when test="m=6">June</xsl:when>
  <xsl:when test="m=7">July</xsl:when>
  <xsl:when test="m=8">August</xsl:when>
  <xsl:when test="m=9">September</xsl:when>
  <xsl:when test="m=10">October</xsl:when>
  <xsl:when test="m=11">November</xsl:when>
  <xsl:when test="m=12">December</xsl:when>
  </xsl:choose>
  <xsl:text> </xsl:text>
  <xsl:number value="y"/>
</xsl:template>

</xsl:stylesheet>