<?xml version="1.0" encoding="utf8"?>
<!--

$Id: fo-slides.xsl,v 2.7 2004/10/13 23:00:14 jmates Exp $

The author disclaims all copyrights and releases this document into
the public domain.

For conversion of eolas documents into XSL-FO which procudes a set of
"slides" suitable for presentation.  This imposes restrictions on the
source eolas document, e.g. making sure slides do not spill over into
empty subsequent pages.  Bear in mind XSL-FO is not very suited to the
layout-driven needs of slides for presentation, so SMIL or similar may
be a better choice for you.

-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fox="http://xml.apache.org/fop/extensions" version="1.0">
  <xsl:import href="fo-shared.xsl"/>
<!--  <xsl:strip-space elements="*"/> -->
  <xsl:template match="/">
    <fo:root>
      <fo:layout-master-set>
<!-- intro/summary page setup -->
        <fo:simple-page-master margin-right="5mm" margin-left="5mm" margin-bottom="5mm" margin-top="5mm" page-width="140mm" page-height="105mm" master-name="summary">
          <fo:region-body/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="summary-page">
          <fo:single-page-master-reference master-reference="summary"/>
        </fo:page-sequence-master>
<!-- regular slides, with page header/footers for metadata -->
        <fo:simple-page-master margin-right="5mm" margin-left="5mm" margin-bottom="5mm" margin-top="5mm" page-width="140mm" page-height="105mm" master-name="slide">
<!-- these need fiddling, e.g. to get header/footer properly placed... -->
          <fo:region-body margin-top="5mm"/>
          <fo:region-before extent="10mm" region-name="xsl-region-before"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="slide-pages">
          <fo:repeatable-page-master-reference master-reference="slide"/>
        </fo:page-sequence-master>
      </fo:layout-master-set>
      <xsl:apply-templates/>
    </fo:root>
  </xsl:template>
<!-- eolas root element -->
  <xsl:template match="eolas">
<!-- Fop-specific stuff to generate PDF outline/bookmarks -->
    <fox:outline internal-destination="{generate-id(summary/title)}">
      <fox:label>
        <xsl:value-of select="summary/title"/>
      </fox:label>
    </fox:outline>
    <fox:outline internal-destination="roadmap">
      <fox:label>
        <xsl:text>Topics to Cover</xsl:text>
      </fox:label>
    </fox:outline>
    <xsl:apply-templates select="section" mode="fox-outline"/>
    <fox:outline internal-destination="conclusion">
      <fox:label>
        <xsl:text>Conclusion</xsl:text>
      </fox:label>
    </fox:outline>
    <xsl:apply-templates select="summary"/>
    <xsl:call-template name="roadmap"/>
    <fo:page-sequence master-reference="slide-pages">
      <xsl:call-template name="standard-header"/>
      <fo:flow flow-name="xsl-region-body">
        <xsl:apply-templates select="section"/>
      </fo:flow>
    </fo:page-sequence>
    <xsl:call-template name="conclusion"/>
  </xsl:template>
  <xsl:template name="roadmap">
    <fo:page-sequence master-reference="slide-pages">
      <xsl:call-template name="standard-header"/>
      <fo:flow flow-name="xsl-region-body">
        <fo:block xsl:use-attribute-sets="title" id="roadmap">
          <fo:wrapper xsl:use-attribute-sets="standard-header">
            <fo:marker marker-class-name="section">
              <xsl:value-of select="//summary/title"/>
            </fo:marker>
          </fo:wrapper>
          <xsl:text>Topics to Cover</xsl:text>
        </fo:block>
        <fo:list-block xsl:use-attribute-sets="list.block">
          <xsl:for-each select="section">
            <fo:list-item xsl:use-attribute-sets="list.item">
              <fo:list-item-label end-indent="label-end()">
                <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
              </fo:list-item-label>
              <fo:list-item-body start-indent="body-start()">
                <fo:block xsl:use-attribute-sets="list">
                  <fo:basic-link internal-destination="{generate-id()}">
                    <xsl:value-of select="title"/>
                  </fo:basic-link>
                </fo:block>
              </fo:list-item-body>
            </fo:list-item>
          </xsl:for-each>
        </fo:list-block>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
  <xsl:template match="summary/version">
<!--    <xsl:if test="version"> -->
    <fo:block xsl:use-attribute-sets="summary computer" font-size="6pt">
      <xsl:value-of select="."/>
    </fo:block>
    <fo:block xsl:use-attribute-sets="summary computer" font-size="6pt">
      <xsl:text>$Id: fo-slides.xsl,v 2.7 2004/10/13 23:00:14 jmates Exp $</xsl:text>
    </fo:block>
<!--    </xsl:if> -->
  </xsl:template>
<!-- summary info into "intro" page -->
  <xsl:template match="summary">
    <fo:page-sequence master-reference="slide-pages">
      <xsl:call-template name="standard-header"/>
      <fo:flow flow-name="xsl-region-body">
<!-- KLUGE table to align summary stuff on single page until I can figure out a more elegant means of doing so -->
        <fo:table inline-progression-dimension="130mm" table-layout="fixed">
          <fo:table-column column-number="1" column-width="proportional-column-width(100)"/>
          <fo:table-body>
            <fo:table-row height="15mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:apply-templates select="title"/>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="15mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:apply-templates select="description"/>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="10mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:if test="author">
                  <fo:block xsl:use-attribute-sets="general summary">
                    <xsl:for-each select="author">
                      <xsl:sort select="first-name"/>
                      <xsl:sort select="last-name"/>
                      <xsl:choose>
                        <xsl:when test="@xlink:href">
                          <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
                            <xsl:value-of select="first-name"/>
                            <xsl:if test="last-name">
                              <xsl:text> </xsl:text>
                              <xsl:value-of select="last-name"/>
                            </xsl:if>
                          </fo:basic-link>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:value-of select="first-name"/>
                          <xsl:if test="last-name">
                            <xsl:text> </xsl:text>
                            <xsl:value-of select="last-name"/>
                          </xsl:if>
                        </xsl:otherwise>
                      </xsl:choose>
                      <xsl:if test="not(position()=last())">
                        <xsl:text>, </xsl:text>
                      </xsl:if>
                    </xsl:for-each>
                  </fo:block>
                </xsl:if>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="15mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:if test="contributor">
                  <fo:block xsl:use-attribute-sets="general summary">
                    <xsl:text>(</xsl:text>
                    <xsl:for-each select="contributor">
                      <xsl:sort select="first-name"/>
                      <xsl:sort select="last-name"/>
<!-- more elegant way of doing this? -->
                      <xsl:choose>
                        <xsl:when test="@xlink:href">
                          <fo:basic-link xsl:use-attribute-sets="link" external-destination="{@xlink:href}">
                            <xsl:value-of select="first-name"/>
                            <xsl:if test="last-name">
                              <xsl:text> </xsl:text>
                              <xsl:value-of select="last-name"/>
                            </xsl:if>
                          </fo:basic-link>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:value-of select="first-name"/>
                          <xsl:if test="last-name">
                            <xsl:text> </xsl:text>
                            <xsl:value-of select="last-name"/>
                          </xsl:if>
                        </xsl:otherwise>
                      </xsl:choose>
                      <xsl:if test="not(position()=last())">
                        <xsl:text>, </xsl:text>
                      </xsl:if>
                    </xsl:for-each>
                    <xsl:text>)</xsl:text>
                  </fo:block>
                </xsl:if>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="10mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:apply-templates select="source"/>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="10mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:apply-templates select="date"/>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="10mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:apply-templates select="rights"/>
              </fo:table-cell>
            </fo:table-row>
            <fo:table-row height="5mm">
              <fo:table-cell border="none 0.25mm black">
                <xsl:apply-templates select="version"/>
              </fo:table-cell>
            </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
  <xsl:template name="conclusion">
    <fo:page-sequence master-reference="slide-pages">
      <xsl:call-template name="standard-header"/>
      <fo:flow flow-name="xsl-region-body">
<!-- KLUGE table to fill single page until I can figure out a more elegant means of doing so -->
        <fo:table inline-progression-dimension="130mm" table-layout="fixed">
          <fo:table-column column-number="1" column-width="proportional-column-width(100)"/>
          <fo:table-body>
            <fo:table-row height="95mm" background-image="url(http://sial.org/_xs/eolas/orei-background.gif)">
              <fo:table-cell border="none 0.25mm black">
                <fo:block xsl:use-attribute-sets="title" id="conclusion"><fo:wrapper xsl:use-attribute-sets="standard-header"><fo:marker marker-class-name="section"><xsl:value-of select="//summary/title"/></fo:marker></fo:wrapper>
                  Conclusion
                </fo:block>
                <fo:list-block xsl:use-attribute-sets="list.block">
                  <fo:list-item xsl:use-attribute-sets="list.item">
                    <fo:list-item-label end-indent="label-end()">
                      <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
                    </fo:list-item-label>
                    <fo:list-item-body start-indent="body-start()">
                      <fo:block xsl:use-attribute-sets="list">
                        Questions, comments, or ideas?
                      </fo:block>
                    </fo:list-item-body>
                  </fo:list-item>
                  <fo:list-item xsl:use-attribute-sets="list.item">
                    <fo:list-item-label end-indent="label-end()">
                      <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
                    </fo:list-item-label>
                    <fo:list-item-body start-indent="body-start()">
                      <xsl:apply-templates select="/eolas/summary/source" mode="not-summary"/>
                    </fo:list-item-body>
                  </fo:list-item>
                </fo:list-block>
              </fo:table-cell>
            </fo:table-row>
          </fo:table-body>
        </fo:table>
<!-- empty trailing block for total page count -->
        <fo:block id="finis"/>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
<!-- shows where we are, have been, coming to -->
  <xsl:template name="roadmap-progress">
    <fo:block xsl:use-attribute-sets="title" color="#666666">
      <fo:wrapper xsl:use-attribute-sets="standard-header">
        <fo:marker marker-class-name="section">
          <xsl:value-of select="//summary/title"/>
        </fo:marker>
      </fo:wrapper>
      <xsl:text>Outline Progress…</xsl:text>
    </fo:block>
    <fo:list-block xsl:use-attribute-sets="list.block">
      <xsl:if test="count(preceding-sibling::section) &gt; 1">
        <fo:list-item space-after="0pt" space-before="0pt">
          <fo:list-item-label end-indent="label-end()">
            <fo:block/>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block xsl:use-attribute-sets="list">
              <xsl:text>…</xsl:text>
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:if>
<!-- previous sections -->
      <xsl:for-each select="preceding-sibling::section[position() &lt;= 1]">
        <fo:list-item xsl:use-attribute-sets="list.item">
          <fo:list-item-label end-indent="label-end()">
            <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block xsl:use-attribute-sets="list" color="#666666">
              <fo:basic-link internal-destination="{generate-id()}">
                <xsl:value-of select="title"/>
              </fo:basic-link>
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:for-each>
<!-- current section -->
      <fo:list-item xsl:use-attribute-sets="list.item">
        <fo:list-item-label end-indent="label-end()">
          <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
          <fo:block xsl:use-attribute-sets="list" color="#FF0000">
            <fo:basic-link internal-destination="{generate-id()}">
              <xsl:value-of select="title"/>
            </fo:basic-link>
          </fo:block>
        </fo:list-item-body>
      </fo:list-item>
<!-- children of current -->
      <xsl:if test="section">
        <fo:list-item>
          <fo:list-item-label end-indent="label-end()">
            <fo:block xsl:use-attribute-sets="list.label"/>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:list-block xsl:use-attribute-sets="list.block">
              <xsl:for-each select="section[position() &lt;= 4]">
                <fo:list-item xsl:use-attribute-sets="list.item">
                  <fo:list-item-label end-indent="label-end()">
                    <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
                  </fo:list-item-label>
                  <fo:list-item-body start-indent="body-start()">
                    <fo:block xsl:use-attribute-sets="list">
                      <fo:basic-link internal-destination="{generate-id()}">
                        <xsl:value-of select="title"/>
                      </fo:basic-link>
                    </fo:block>
                  </fo:list-item-body>
                </fo:list-item>
              </xsl:for-each>
              <xsl:if test="count(section) &gt; 4">
                <fo:list-item space-after="0pt" space-before="0pt">
                  <fo:list-item-label end-indent="label-end()">
                    <fo:block/>
                  </fo:list-item-label>
                  <fo:list-item-body start-indent="body-start()">
                    <fo:block xsl:use-attribute-sets="list">
                      <xsl:text>…</xsl:text>
                    </fo:block>
                  </fo:list-item-body>
                </fo:list-item>
              </xsl:if>
            </fo:list-block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:if>
<!-- remaining sections at same level -->
      <xsl:for-each select="following-sibling::section[position() &lt;= 2]">
        <fo:list-item xsl:use-attribute-sets="list.item">
          <fo:list-item-label end-indent="label-end()">
            <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block xsl:use-attribute-sets="list">
              <fo:basic-link internal-destination="{generate-id()}">
                <xsl:value-of select="title"/>
              </fo:basic-link>
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:for-each>
      <xsl:if test="count(following-sibling::section) &gt; 2">
        <fo:list-item space-after="0pt" space-before="0pt">
          <fo:list-item-label end-indent="label-end()">
            <fo:block/>
          </fo:list-item-label>
          <fo:list-item-body start-indent="body-start()">
            <fo:block xsl:use-attribute-sets="list">
              <xsl:text>…</xsl:text>
            </fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </xsl:if>
    </fo:list-block>
  </xsl:template>
  <xsl:template match="section">
<!-- "where we've been, going to" summary pages -->
    <xsl:if test="count(descendant::section) &gt; 1">
      <fo:block break-before="page">
        <xsl:call-template name="roadmap-progress"/>
      </fo:block>
    </xsl:if>
    <xsl:choose>
<!-- KLUGE When section element counts is total (minus title), generate sub-section links, as otherwise get a blank page in output.  Cannot hide output, as need something for internal section links to target. -->
      <xsl:when test="count(section) = (count(*) - 1)">
        <fo:block break-before="page" id="{generate-id()}">
          <xsl:apply-templates select="title"/>
<!-- children of current -->
          <fo:list-block xsl:use-attribute-sets="list.block">
            <xsl:for-each select="section[position() &lt;= 8]">
              <fo:list-item xsl:use-attribute-sets="list.item">
                <fo:list-item-label end-indent="label-end()">
                  <fo:block xsl:use-attribute-sets="list.label">•</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                  <fo:block xsl:use-attribute-sets="list">
                    <fo:basic-link internal-destination="{generate-id()}">
                      <xsl:value-of select="title"/>
                    </fo:basic-link>
                  </fo:block>
                </fo:list-item-body>
              </fo:list-item>
            </xsl:for-each>
            <xsl:if test="count(section) &gt; 8">
              <fo:list-item space-after="0pt" space-before="0pt">
                <fo:list-item-label end-indent="label-end()">
                  <fo:block/>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                  <fo:block xsl:use-attribute-sets="list">
                    <xsl:text>…</xsl:text>
                  </fo:block>
                </fo:list-item-body>
              </fo:list-item>
            </xsl:if>
          </fo:list-block>
          <xsl:apply-templates select="section"/>
        </fo:block>
      </xsl:when>
      <xsl:otherwise>
        <fo:block break-before="page" id="{generate-id()}">
          <xsl:apply-templates/>
        </fo:block>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
