<?xml version="1.0" encoding="UTF-8"?>

<!-- This stylesheet queries the contents of some of the other examples and
     generates a fairly simple multimedia catalog. It is meant to show how
     some simple formatting can be accomplished with formatting objects.

     See minimal-catalog.xsl for an example of an unformatted result. -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<!-- This variable is set by the installation procedure to the absolute
     path of the Stylus Studio examples directory on your system. -->
<xsl:variable name="examples-dir" select="'..'"/>

<xsl:template match="/">
  <fo:root>
    <fo:layout-master-set>
      <!-- Define the cover page. -->
      <fo:simple-page-master master-name="cover" page-height="8.5in"
                             page-width="5.5in" margin-top="0.25in"
                             margin-bottom="0.25in" margin-left="0.25in"
                             margin-right="0.25in">
        <fo:region-body margin-top="0.25in" margin-bottom="0.25in"/>
      </fo:simple-page-master>

      <!-- Define a body (or default) page. -->
      <fo:simple-page-master master-name="default-master" page-height="8.5in"
                             page-width="5.5in" margin-top="0.25in"
                             margin-bottom="0.25in">

        <!-- Central part of page -->
        <fo:region-body column-count="2" margin-top="0.25in"
                        margin-bottom="0.25in"/>

        <!-- Header -->
        <fo:region-before extent="0.25in"/>

        <!-- Footer -->
        <fo:region-after extent="0.25in"/>
      </fo:simple-page-master>
    </fo:layout-master-set>

    <!-- The data to be diplayed in the pages, cover page first -->
    <fo:page-sequence master-reference="cover">
      <fo:flow flow-name="xsl-region-body">
        <fo:block text-align="center" font-size="14.0pt">
          <xsl:text>Stylus Studio Multimedia Catalog</xsl:text>
        </fo:block>
      </fo:flow>
    </fo:page-sequence>

    <!-- Body page -->
    <fo:page-sequence master-reference="default-master">

      <!-- Define the contents of the header. -->
      <fo:static-content flow-name="xsl-region-before">
        <fo:block font-size="8.0pt" font-family="serif" padding-after="2.0pt"
                  space-before="4.0pt" text-align="center"
                  border-bottom-style="solid" border-bottom-width="1.0pt">
          <xsl:text>Stylus Studio Multimedia Catalog of Video and Computer Books</xsl:text>
        </fo:block>
      </fo:static-content>

      <!-- Define the contents of the footer. -->
      <fo:static-content flow-name="xsl-region-after">
        <fo:block font-size="8.0pt" font-family="sans-serif" padding-after="2.0pt"
                  space-before="4.0pt" text-align="center"
                  border-top-style="solid" border-bottom-width="1.0pt">
                  <xsl:text>Page </xsl:text>
                  <fo:page-number/>
        </fo:block>
      </fo:static-content>

      <!-- The main contents of the body page, that is, the catalog
           entries -->
      <fo:flow flow-name="xsl-region-body">
        <fo:block font-size="10.0pt" font-family="serif">
	      <xsl:apply-templates select="/result/videos/video | document('../simpleMappings/books.xml')/books/book | document('../simpleMappings/catalog.xml')/Catalog/Book">
          <!-- Use the contains() function to take into account that the title
               element name sometimes starts with a lowercase "t" and sometimes with
               an uppercase "T". -->
          <xsl:sort select="*[contains(name(), 'itle')]"/>
        </xsl:apply-templates>
        </fo:block>
      </fo:flow>
    </fo:page-sequence>
  </fo:root>
</xsl:template>

<!-- Format entries from books.xml -->
<xsl:template match="book">
  <xsl:call-template name="entry">
    <xsl:with-param name="title" select="title"/>
    <xsl:with-param name="authorList" select="authors/author"/>
    <xsl:with-param name="description" select="concat('This book discusses ', subject, '.')"/>
  </xsl:call-template>
</xsl:template>

<!-- Format entries from catalogs.xml -->
<xsl:template match="Book">
  <xsl:call-template name="entry">
    <xsl:with-param name="title" select="Title"/>
    <xsl:with-param name="authorList" select="Authors/Author"/>
    <xsl:with-param name="description" select="Abstract"/>
  </xsl:call-template>
</xsl:template>

<!-- Format entries from video.xml -->
<xsl:template match="video">
  <xsl:call-template name="entry">
    <xsl:with-param name="title" select="title"/>
    <xsl:with-param name="authorList" select="director"/>
    <xsl:with-param name="description" select="details"/>
    <xsl:with-param name="imageFile" select="concat($examples-dir, '/VideoCenter/images/video/', @id, '.gif')"/>
  </xsl:call-template>
</xsl:template>

<!-- All entries have the same basic format: a title, an author (or
     director), a description and an optional graphic. Each type of entry is
     taken care of by matching one of the above templates. Those templates, in
     turn, call this one to do the real formatting. -->
<xsl:template name="entry">
  <xsl:param name="title"/>
  <xsl:param name="authorList"/>
  <xsl:param name="description"/>
  <xsl:param name="imageFile" select="''"/>

  <!-- Put entire entry within a single block. -->
  <fo:block space-before="4.0pt" space-after="4.0pt" start-indent="0.25in" end-indent="0.25in">

    <!-- Title -->
    <fo:block font-family="sans-serif" font-size="10.0pt" space-after="2.0pt">
      <xsl:value-of select="$title"/>
    </fo:block>

    <!-- Author (Director) -->
    <fo:block font-family="sans-serif" space-after="2.0pt">
      <xsl:text>by </xsl:text>
      <xsl:call-template name="comma-separated-list">
        <xsl:with-param name="list" select="$authorList"/>
      </xsl:call-template>
    </fo:block>

    <!-- Image file (optional) -->
    <xsl:if test="$imageFile">
      <fo:block text-align="center">
        <fo:external-graphic src="{$imageFile}"/>
      </fo:block>
    </xsl:if>

    <!-- Description -->
    <fo:block>
      <xsl:value-of select="$description"/>
    </fo:block>
  </fo:block>
</xsl:template>
  
<!-- Useful template for listing multiple items (such as authors). -->
<xsl:template name="comma-separated-list">
  <xsl:param name="list"/>
  <!-- Always display the first item. -->
  <xsl:value-of select="$list[1]"/>
  <!-- Display the remaining items. -->
  <xsl:for-each select="$list[position() > 1]">
    <xsl:choose>
      <!-- This is not the last one, so separate with a comma. -->
      <xsl:when test="last() > position()">
        <xsl:text>, </xsl:text>
      </xsl:when>
      <!-- This is the last one, so use "and" instead of a comma. -->
      <xsl:otherwise><xsl:text> and </xsl:text></xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="."/>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

<!-- Stylus Studio meta-information - (c)2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="video" userelativepaths="yes" externalpreview="no" url="..\VideoCenter\videos.xml" htmlbaseurl="" processortype="internal" commandline="" additionalpath="" additionalclasspath="" postprocessortype="fop" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->