<?xml version="1.0" encoding="UTF-8"?>
<!-- Stylesheet used to generate SVG content and slides -->
<!-- I. Herman $Date: 2004/02/13 08:40:27 $ -->
<!--
     Copyright (c) 2003 W3C
     See http://www.w3.org/Consortium/Legal/copyright-software-19980720
     for W3C software licensing (open source compatible)
     Author: Ivan Herman <ivan@w3.org>     
-->
<!-- *********************************************************************** -->
<!-- FOR XSLT 2.0: the extension elements related to SAXON should be deleted -->
<!-- *********************************************************************** -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="saxon" xmlns:saxon="http://icl.com/saxon" xmlns:x="http://www.w3.org/1999/xhtml" xmlns:slide="http://www.w3.org/Consortium/Offices/Presentation/xsltSlidemaker"
xmlns:xlink="http://www.w3.org/1999/xlink">
    <xsl:include href="svgCommon.xsl"/>
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="no"/>
    <!-- ======================================================= -->
    <!--     Parameters governing the behaviour of the script    -->
    <!-- ======================================================= -->
    <!--
        If SVG-s are manipulated, the relative URL-s in the files
        have to be changed on the fly. There are two modes for this:
        relative and absolute.
    -->
    <xsl:param name="SVGURLs" select="'relative'"/>
    <!--
        Generate a separete title page or not
    -->
    <xsl:param name="TitlePage" select="'true'"/>
    <!--
        Generate keypress script or not
    -->
    <xsl:param name="KeyPress" select="'true'"/>
    <!-- 
        Generate navigation arrows or not
    -->
    <xsl:param name="Navigation" select="'true'"/>
    <!--
        Whether the links should refer to 'svgz' or to 'svg'
    -->
    <xsl:param name="ZippedReferences" select="'false'"/>
    <xsl:variable name="Ext">
        <xsl:choose>
            <xsl:when test="$ZippedReferences = 'true'">.svgz</xsl:when>
            <xsl:otherwise>.svg</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <!--
        Some common functions may work differently whether one or several svg slides are generated
    -->
    <xsl:variable name="SingleSVG" select="'false'"/>
    <!-- 
        The real meat: go through the full input's body.
    -->
    <xsl:template match="x:html/x:body">
        <xsl:call-template name="getStyleSheets"/>
        <xsl:text>&#xA;</xsl:text>
        <svg xmlns="http://www.w3.org/2000/svg" xml:lang="{$documentLanguage}">
            <xsl:attribute name="viewBox"><xsl:value-of select="concat('0 0 ',$W,' ',$H)"/></xsl:attribute>
            <!-- If there are style elements in the original header, they are copied here! -->
 			<xsl:call-template name="addMetadata">
				<xsl:with-param name="title" select="$OverallTitle"/> 
			</xsl:call-template>
           <xsl:for-each select="/x:html/x:head/x:style">
                <style type="text/css" xmlns="http://www.w3.org/2000/svg">
                    <xsl:copy-of select="./text()"/>
                </style>
            </xsl:for-each>
            <defs>
                <xsl:call-template name="frameDef"/>
                <xsl:call-template name="title_effects"/>
                <xsl:call-template name="logoDef"/>
                <g id="tocr">
                    <rect x="-5" y="-{($dColTH div 2)}" class="tocItem" width="{$dColW - 25}" height="{$dColTH - 10}"/>
                </g>
                <xsl:call-template name="slideBackgroundPattern"/>
            </defs>
            <clipPath id="clPP" clipPathUnits="userSpaceOnUse">
                <rect x="-5" y="-{($dColTH div 2)}" fill="none" stroke="black" width="{$dColW - 25}" height="{$dColTH - 10}"/>
            </clipPath>
            <style type="text/css">
                <xsl:text>text.toc { font-size:</xsl:text>
                <xsl:value-of select="$tocFontS"/>
                <xsl:text>;}</xsl:text>
            </style>
            <xsl:call-template name="createSlideTitle">
                <xsl:with-param name="title" select="$OverallTitle"/>
            </xsl:call-template>
            <g class="slideContent">
                <xsl:attribute name="transform">
                  <xsl:value-of select="concat('translate(',$sX,' ',$sY,')')"/>
                </xsl:attribute>
                <xsl:comment>Slide content area, to possibly give another colour</xsl:comment>
                <rect class="slideContent" width="{$sW + 10}" height="{$sH + 10}" x="-5" y="-5"/>
                <xsl:comment>The nice frame (just for the fun of it...</xsl:comment>
                <use xlink:href="#frame"/>
                <g transform="translate(10)">
                    <xsl:attribute name="transform">
                      <xsl:value-of select="concat('translate(20,',1.5*$dColTH,')')"/>
                    </xsl:attribute>
                    <xsl:if test="$TitlePage = 'true'">
                      <g transform="translate(0,0)">
                        <use xlink:href="#tocr"/>
                        <a xlink:href="{concat('0',$Ext)}">
                          <text class="toc" y="3" clip-path="url(#clPP)">0. [Title Page]</text>
                        </a>
                      </g>
                    </xsl:if>
                    <xsl:for-each select="x:div[@class='slide']">                        
                        <xsl:if test="not(@slide:noTOC='true')">
                            <xsl:variable name="x" select="floor(((position()) div $dColH)) * $dColW"/>
                            <xsl:variable name="y" select="((position()) mod $dColH) * $dColTH"/>
                            <g>
                                <xsl:attribute name="transform">
                                  <xsl:value-of select="concat('translate(',$x,' ',$y,')')"/>
                                </xsl:attribute>
                                <use xlink:href="#tocr"/>
                                <a>
                                    <xsl:attribute name="xlink:href">
                                      <xsl:value-of select="concat(position(),$Ext)"/>
                                    </xsl:attribute>
                                    <text class="toc" y="3" clip-path="url(#clPP)">
                                        <xsl:value-of select="position()"/>
                                        <xsl:text>. </xsl:text>
                                        <xsl:value-of select="x:h1"/>
                                    </text>
                                </a>
                            </g>
                        </xsl:if>
                    </xsl:for-each>
                </g>
            </g>
            <!-- Add the signature to the bottom -->
            <xsl:call-template name="signature">
                <xsl:with-param name="slideNumber" select="0"/>
            </xsl:call-template>
        </svg>
        <!-- Generation of a separate title page, if required -->
        <xsl:if test="$TitlePage = 'true'">
            <xsl:message>Generate Title Page</xsl:message>
            <!-- FOR XSLT: the element should be <xsl:result-document href="0.svg"> -->
            <saxon:output href="0.svg">
                <xsl:call-template name="getStyleSheets"/>
                <svg id="top_" xmnls="http://www.w3.org/2000/svg" xml:lang="{$documentLanguage}">
                    <xsl:attribute name="viewBox"><xsl:value-of select="concat('0 0 ',$W,' ',$H)"/></xsl:attribute>
                    <!-- Add navigation javascript -->
                    <xsl:if test="$KeyPress = 'true'">
                        <xsl:attribute name="onload">Slide_init(evt);</xsl:attribute>
                        <xsl:call-template name="navigationJS">
                            <xsl:with-param name="previous">dummy</xsl:with-param>
                            <xsl:with-param name="next" select="concat('1',$Ext)"/>
                        </xsl:call-template>
                    </xsl:if>
                    <!-- If there are style elements in the original header, they are copied here! -->
                    <xsl:for-each select="/x:html/x:head/x:style">
                        <style type="text/css" xmlns="http://www.w3.org/2000/svg">
                            <xsl:copy-of select="./text()"/>
                        </style>
                    </xsl:for-each>
                    <defs>
                        <xsl:call-template name="linkFigures"/>
                        <xsl:call-template name="title_effects"/>
                        <xsl:call-template name="frameDef"/>
                        <xsl:call-template name="logoDef"/>
                        <xsl:call-template name="slideBackgroundPattern"/>
                    </defs>
                    <xsl:call-template name="titleBackground">
                        <xsl:with-param name="title" select="'Title Page'"/>
                    </xsl:call-template>
                    <xsl:if test="$Navigation = 'true'">
                        <g class="slideTitleArea">
                            <a xlink:href="{$indexPageSVG}">
                                <use xlink:href="#upArrow">
                                    <xsl:attribute name="transform"><xsl:value-of select="concat('translate(',$W - $sXDefault - 50,',40)')"/></xsl:attribute>
                                </use>
                            </a>
                            <xsl:comment>Right Arrow</xsl:comment>
                            <a>
                                <xsl:attribute name="xlink:href">
                                    <xsl:value-of select="concat('1',$Ext)"/>
                                </xsl:attribute>
                                <use xlink:href="#rightArrow" id="forward_arrow">
                                    <xsl:attribute name="transform"><xsl:value-of select="concat('translate(',$W - $sXDefault - 16,',40)')"/></xsl:attribute>
                                </use>
                            </a>
                        </g>
                    </xsl:if>
                    <xsl:call-template name="titlePageContent"/>
                    <!-- Add the tooltips; these should cover everything else, hence their position in the file -->
                    <xsl:call-template name="tooltips">
                        <xsl:with-param name="position" select="concat('translate(',$W - $sXDefault - 38,',60)')"/>
                        <xsl:with-param name="next" select="x:div[@class='slide'][position()=1]/x:h1"/>
                        <xsl:with-param name="back" select="'back_arrow'"/>
                        <xsl:with-param name="forward" select="'forward_arrow'"/>
                    </xsl:call-template>
                </svg>
            </saxon:output>
        </xsl:if>
        <!-- Generation of each separate slide file through a cycle on all slide div-s -->
        <xsl:for-each select="x:div[@class='slide']">
            <!-- Now the output file can be generated -->
            <xsl:variable name="outfile" select="concat(position(),'.svg')"/>
            <xsl:message>Generate <xsl:value-of select="$outfile"/>
            </xsl:message>
            <!-- ******************************************************************************** -->
            <!-- FOR XSLT 2.0: the element below should be <xsl:result-document href="{$outfile}>" -->
            <!-- ******************************************************************************** -->
            <saxon:output href="{$outfile}">
                <xsl:call-template name="getStyleSheets"/>
                <xsl:if test="count(descendant::x:object[@type='image/svg+xml'])!=0">
                    <xsl:variable name="css">
                        <xsl:call-template name="getCssSVG">
                            <xsl:with-param name="obj" select="descendant::x:object[@type='image/svg+xml'][1]"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:if test="string-length($css) != 0">
                        <xsl:text>&#xA;</xsl:text>
                        <xsl:processing-instruction name="xml-stylesheet">href="<xsl:value-of select="$css"/>" type="text/css"</xsl:processing-instruction>
                        <xsl:text>&#xA;</xsl:text>
                    </xsl:if>
                </xsl:if>
                <svg id="top_" xmlns="http://www.w3.org/2000/svg" xml:lang="{$documentLanguage}">
                    <xsl:attribute name="viewBox"><xsl:value-of select="concat('0 0 ',$W,' ',$H)"/></xsl:attribute>
                    <!-- Add navigation javascript -->
                    <xsl:if test="$KeyPress = 'true'">
                        <xsl:attribute name="onload">Slide_init(evt);</xsl:attribute>
                        <xsl:call-template name="navigationJS">
                            <xsl:with-param name="previous">
                                <xsl:choose>
                                    <xsl:when test="position()!=1">
                                        <xsl:value-of select="concat(position()-1,$Ext)"/>
                                    </xsl:when>
                                    <xsl:when test="$TitlePage = 'true'">
                                        <xsl:value-of select="concat('0',$Ext)"/>
                                    </xsl:when>
                                    <xsl:otherwise>dummy</xsl:otherwise>
                                </xsl:choose>
                            </xsl:with-param>
                            <xsl:with-param name="next">
                                <xsl:choose>
                                    <xsl:when test="position()!=last()">
                                        <xsl:value-of select="concat(position()+1,$Ext)"/>
                                    </xsl:when>
                                    <xsl:otherwise>dummy</xsl:otherwise>
                                </xsl:choose>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:if>
  					<xsl:call-template name="addMetadata">
						<xsl:with-param name="title" select="./x:h1"/> 
					</xsl:call-template>
                    <!-- Add flip-flop javascript -->
                    <xsl:call-template name="flipScript"/>                    
                    <!-- If there are style elements in the original header, they are copied here! -->
                    <xsl:for-each select="/x:html/x:head/x:style">
                        <style type="text/css" xmlns="http://www.w3.org/2000/svg">
                            <xsl:copy-of select="./text()"/>
                        </style>
                    </xsl:for-each>
                    <defs>
                        <xsl:call-template name="linkFigures"/>
                        <xsl:call-template name="title_effects"/>
                        <xsl:call-template name="frameDef"/>
                        <xsl:call-template name="logoDef"/>
                        <xsl:call-template name="slideBackgroundPattern"/>
                    </defs>
                    <xsl:call-template name="createSlideTitle">
                        <xsl:with-param name="title" select="./x:h1"/>
                    </xsl:call-template>
                    <xsl:if test="$Navigation = 'true'">
                        <g class="slideTitleArea">
                            <xsl:attribute name="transform"><xsl:value-of select="concat('translate(',$W - $sXDefault - 86,',40)')"/></xsl:attribute>
                            <xsl:choose>
                                <xsl:when test="position()!=1">
                                    <xsl:comment>Left arrow</xsl:comment>
                                    <a>
                                        <xsl:attribute name="xlink:href"><xsl:value-of select="concat(position()-1,$Ext)"/></xsl:attribute>
                                        <use xlink:href="#leftArrow" id="back_arrow"/>
                                    </a>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:if test="$TitlePage = 'true'">
                                        <xsl:comment>Left arrow to titlepage</xsl:comment>
                                        <a>
                                            <xsl:attribute name="xlink:href">
                                                <xsl:value-of select="concat('0',$Ext)"/>
                                            </xsl:attribute>
                                            <use xlink:href="#leftArrow" id="back_arrow"/>
                                        </a>
                                    </xsl:if>
                                </xsl:otherwise>
                            </xsl:choose>
                            <a xlink:href="{$indexPageSVG}">
                                <use xlink:href="#upArrow">
                                    <xsl:attribute name="transform"><xsl:value-of select="concat('translate(',34,')')"/></xsl:attribute>
                                </use>
                            </a>
                            <xsl:if test="position()!=last()">
                                <xsl:comment>Right Arrow</xsl:comment>
                                <a>
                                    <xsl:attribute name="xlink:href"><xsl:value-of select="concat(position()+1,$Ext)"/></xsl:attribute>
                                    <use xlink:href="#rightArrow" id="forward_arrow">
                                        <xsl:attribute name="transform"><xsl:value-of select="concat('translate(',68,',0)')"/></xsl:attribute>
                                    </use>
                                </a>
                            </xsl:if>
                        </g>
                    </xsl:if>
                    <xsl:call-template name="createSlideContent">
                        <xsl:with-param name="slide" select="."/>
                        <xsl:with-param name="pos" select="position()"/>
                    </xsl:call-template>
                    <!-- Add the tooltips; these should cover everything else, hence their position in the file -->
                    <xsl:call-template name="tooltips">
                        <xsl:with-param name="position" select="concat('translate(',$W - $sXDefault - 38,',60)')"/>
                        <xsl:with-param name="previous" select="preceding-sibling::x:div[position()=1]/x:h1"/>
                        <xsl:with-param name="next" select="following-sibling::x:div[position()=1]/x:h1"/>
                        <xsl:with-param name="back" select="'back_arrow'"/>
                        <xsl:with-param name="forward" select="'forward_arrow'"/>
                    </xsl:call-template>
                </svg>
                <!-- ******************************************************************************* -->
                <!-- FOR XSLT 2.0: the element below should be </xsl:result-document>"               -->
                <!-- ******************************************************************************* -->
            </saxon:output>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
