<?xml version="1.0" encoding="UTF-8"?>
<!-- Common variables, functions, etc, used by all other stylesheets -->
<!-- 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">
    <!-- ================================================================== -->
    <!-- ================================================================== -->
    <!-- Some of the variables below can be adapted by the user             -->
    <!-- for the SVG specific customizations, see the 'svgCommon.xsl' file! -->
    <!-- ================================================================== -->
    <!-- ================================================================== -->
    <xsl:variable name="documentLanguage">
        <xsl:choose>
            <xsl:when test="/x:html/@lang"><xsl:value-of select="/x:html/@lang"/></xsl:when>
            <xsl:otherwise>en</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <!--                Default values for the meta statements              -->
    <!-- Author's default                                                   -->
    <xsl:variable name="authorDefault">Ivan Herman, Head of Offices</xsl:variable>
    <!-- Author URL default                                                 -->
    <xsl:variable name="authorURLDefault">mailto:ivan@w3.org</xsl:variable>
    <!-- Copyright                                                 -->
	<xsl:variable name="copyrightDefault">© W3C (MIT,ERCIM,Keio)</xsl:variable>
    <!-- Basename for the index page, referred to by the 'up' links. The    -->
    <!-- value often depends on the server settings.                        -->
    <xsl:variable name="indexPageDefault">Overview</xsl:variable>
    <!-- Left Arrow Path default                                            -->
    <xsl:variable name="LeftADefault">../icons/left.png</xsl:variable>
    <!-- Right Arrow Path default                                           -->
    <xsl:variable name="RightADefault">../icons/right.png</xsl:variable>
    <!-- Up Arrow Path default                                              -->
    <xsl:variable name="UpADefault">../icons/up.png</xsl:variable>
    <!-- Logo default                                                       -->
    <xsl:variable name="LogoDefault">../icons/w3chome.png</xsl:variable>
    <!-- URL to be used with the logo                                       -->
    <xsl:variable name="LogoURIDefault">http://www.w3.org</xsl:variable>
    <!-- Directory path for the storage of copied svgs files                -->
    <xsl:variable name="svgsDefault">svgs/</xsl:variable>
    <!-- Base value to be used for image size generation; corresponds to    -->
    <!-- 100% height of an image                                            -->
    <xsl:variable name="BasicHeight">600</xsl:variable>
    <!-- Base width to be used for image size generation; corresponds to    -->
    <!-- 100% height of an image                                            -->
    <xsl:variable name="BasicWidth">900</xsl:variable>
	<!-- Copyright default statement                                        -->
    <xsl:variable name="CopyrightDefault">© 1994-2004, W3C (MIT,ERCIM,Keio)</xsl:variable>
	<!-- Copyright link default                                             -->
    <xsl:variable name="CopyrightLinkDefault">http://www.w3.org/Consortium/Legal/copyright-documents</xsl:variable>
	<!-- Organization                                                       -->
    <xsl:variable name="OrganizationDefault">W3C - World Wide Web Consortium</xsl:variable>
    <!-- ======================================================== -->
    <!-- ======================================================== -->
    <!-- If you begin to mess around with thing below, you should -->
    <!-- really know what you are doing!!!!!!!!!!!!!!!!           -->
    <!-- ======================================================== -->
    <!-- ======================================================== -->
    <!-- ======================================================= -->
    <xsl:variable name="NumberOfSlides" select="count(/x:html/x:body/x:div[@class='slide'])"/>
    <!-- ======================================================= -->
    <!-- Extract all kinds of variables from the meta statements -->
    <!-- ======================================================= -->
    <xsl:variable name="OverallTitle" select="/x:html/x:head/x:title"/>
    <xsl:variable name="indexPage">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='indexPage']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='indexPage']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$indexPageDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="indexPageHTML" select="concat($indexPage,'.html')"/>
    <xsl:variable name="indexPageSVG">
        <xsl:choose>
            <xsl:when test="$ZippedReferences = 'true'">
                <xsl:value-of select="concat($indexPage,'.svgz')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat($indexPage,'.svg')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="svgs">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='svgs']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='svgs']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$svgsDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Author">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='Author']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='Author']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$authorDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="AuthorURL">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='AuthorURL']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='AuthorURL']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$authorURLDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Date">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='Date']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='Date']/@content"/>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Event">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='Event']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='Event']/@content"/>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="SlidesURL">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='SlidesURL']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='SlidesURL']/@content"/>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="LeftA">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='LeftArrow']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='LeftArrow']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$LeftADefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="RightA">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='RightArrow']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='RightArrow']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$RightADefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="UpA">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='UpArrow']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='UpArrow']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$UpADefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Logo">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='Logo']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='Logo']/@content"/>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="LogoURI">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='LogoURI']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='LogoURI']/@content"/>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
    </xsl:variable>
     <xsl:variable name="Copyright">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='Copyright']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='Copyright']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$CopyrightDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="CopyrightLink">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='CopyrightLink']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='CopyrightLink']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$CopyrightLinkDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Organization">
        <xsl:choose>
            <xsl:when test="/x:html/x:head/x:meta[@name='Organization']">
                <xsl:value-of select="/x:html/x:head/x:meta[@name='Organization']/@content"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$OrganizationDefault"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
	
    <!-- ================================================================== -->
    <!--                        Basename function                           -->
    <!-- ================================================================== -->
    <!-- 
        A recursive function to generate the basename of a filename. 
        Necessary because the string functions in XPath are a bit poor ;-(
    -->
    <xsl:template name="basename">
        <xsl:param name="in"/>
        <xsl:variable name="left" select="substring-before($in,'/')"/>
        <xsl:variable name="right" select="substring-after($in,'/')"/>
        <xsl:choose>
            <xsl:when test="string-length($left)=0">
                <xsl:value-of select="$in"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="basename">
                    <xsl:with-param name="in" select="$right"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!-- ========================================================================= -->
    <!-- Extracting an attribute value, either from a style attribute or directly  -->
    <!-- ========================================================================= -->
    <!-- Stripping all spaces out of a string -->
    <xsl:template name="strip">
        <xsl:param name="str"/>
        <xsl:value-of select="translate(normalize-space($str),' ','')"/>
    </xsl:template>
    <!-- Get an attribute value from a string with CSS syntax -->
    <!-- Recursive part of the function, entry point below    -->
    <xsl:template name="getAttrR">
        <xsl:param name="key"/>
        <xsl:param name="str"/>
        <xsl:variable name="firstPair" select="substring-before($str,';')"/>
        <xsl:variable name="rest" select="substring-after($str,';')"/>
        <xsl:choose>
            <xsl:when test="string-length($firstPair) != 0">
                <xsl:variable name="fKey" select="substring-before($firstPair,':')"/>
                <xsl:choose>
                    <xsl:when test="$fKey = $key">
                        <!-- Bingo, found it! -->
                        <xsl:value-of select="substring-after($firstPair,':')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <!-- we have to go on... -->
                        <xsl:if test="string-length($rest) != 0">
                            <xsl:call-template name="getAttrR">
                                <xsl:with-param name="key" select="$key"/>
                                <xsl:with-param name="str" select="$rest"/>
                            </xsl:call-template>
                        </xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name="fKey" select="substring-before($str,':')"/>
                <xsl:if test="$fKey = $key">
                    <xsl:value-of select="substring-after($str,':')"/>
                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!-- Get an attribute value from a string with CSS syntax -->
    <!-- Internal entry point, recursive part above           -->
    <xsl:template name="getAttr">
        <xsl:param name="key"/>
        <xsl:param name="str"/>
        <xsl:call-template name="getAttrR">
            <xsl:with-param name="key" select="$key"/>
            <xsl:with-param name="str">
                <xsl:call-template name="strip">
                    <xsl:with-param name="str" select="$str"/>
                </xsl:call-template>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    <!-- The real external entry point!                                                -->
    <!-- return either attribute or a style value. The latter has a higher precendence -->
    <xsl:template name="returnAttr">
        <xsl:param name="element"/>
        <xsl:param name="key"/>
        <xsl:variable name="stVal">
            <xsl:if test="$element/@style">
                <xsl:call-template name="getAttr">
                    <xsl:with-param name="key" select="$key"/>
                    <xsl:with-param name="str" select="$element/@style"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:variable>
        <!-- if the value of stVal is not a zero length string, the return value has been found... -->
        <xsl:choose>
            <xsl:when test="string-length($stVal) != 0">
                <xsl:value-of select="$stVal"/>
            </xsl:when>
            <xsl:otherwise>
                <!-- direct attribute value should be found -->
                <xsl:for-each select="$element/@*">
                    <xsl:if test="local-name(.) = $key">
                        <xsl:value-of select="."/>
                    </xsl:if>
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!-- ================================================================== -->
    <!--         Retrieve the 'from' and 'to' URI patterns for objects      -->
    <!-- ================================================================== -->
    <xsl:template name="getFromURL">
        <xsl:param name="obj"/>
        <xsl:choose>
            <xsl:when test="$obj/@slide:fromPattern">
                <xsl:value-of select="$obj/@slide:fromPattern"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="/x:html/x:head/x:meta[@name='fromPattern']/@content"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getToURL">
        <xsl:param name="obj"/>
        <xsl:param name="orig"/>
        <xsl:choose>
            <xsl:when test="$SVGURLs='relative'">
                <xsl:choose>
                    <xsl:when test="$orig = 'html'">
                        <xsl:choose>
                            <xsl:when test="$obj/@slide:HTMLToPatternRel">
                                <xsl:value-of select="$obj/@slide:HTMLToPatternRel"/>
                            </xsl:when>
                            <xsl:when test="$obj/@slide:toPatternRel">
                                <xsl:value-of select="$obj/@slide:toPatternRel"/>
                            </xsl:when>
                            <xsl:when test="/x:html/x:head/x:meta[@name='HTMLToPatternRel']">
                                <xsl:value-of select="/x:html/x:head/x:meta[@name='HTMLToPatternRel']/@content"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="/x:html/x:head/x:meta[@name='toPatternRel']/@content"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="$obj/@slide:SVGToPatternRel">
                                <xsl:value-of select="$obj/@slide:SVGToPatternRel"/>
                            </xsl:when>
                            <xsl:when test="$obj/@slide:toPatternRel">
                                <xsl:value-of select="$obj/@slide:toPatternRel"/>
                            </xsl:when>
                            <xsl:when test="/x:html/x:head/x:meta[@name='SVGToPatternRel']">
                                <xsl:value-of select="/x:html/x:head/x:meta[@name='SVGToPatternRel']/@content"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="/x:html/x:head/x:meta[@name='toPatternRel']/@content"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$obj/@slide:toPatternAbs">
                        <xsl:value-of select="$obj/@slide:toPatternAbs"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="/x:html/x:head/x:meta[@name='toPatternAbs']/@content"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="getCss">
        <xsl:param name="obj"/>
        <xsl:choose>
            <xsl:when test="$SVGURLs='relative'">
                <xsl:choose>
                    <xsl:when test="$obj/@slide:cssURLRel">
                        <xsl:value-of select="$obj/@slide:cssURLRel"/>
                    </xsl:when>
                    <xsl:when test="/x:html/x:head/x:meta[@name='cssURLRel']/@content">
                        <xsl:value-of select="/x:html/x:head/x:meta[@name='cssURLRel']/@content"/>
                    </xsl:when>
                    <xsl:otherwise/>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$obj/@slide:cssURLAbs">
                        <xsl:value-of select="$obj/@slide:cssURLAbs"/>
                    </xsl:when>
                    <xsl:when test="/x:html/x:head/x:meta[@name='cssURLAbs']/@content">
                        <xsl:value-of select="/x:html/x:head/x:meta[@name='cssURLAbs']/@content"/>
                    </xsl:when>
                    <xsl:otherwise/>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!-- ================================================================== -->
    <!--                     Generation of image size values                -->
    <!--    Used when objects are replaced or extended by images            -->
    <!-- ================================================================== -->
    <xsl:template name="getImgSizes">
        <xsl:param name="object"/>
        <xsl:variable name="hundred">100</xsl:variable>
        <!-- get the file name of the SVG file -->
        <xsl:variable name="fileName" select="$object/@data"/>
        <xsl:variable name="name">
            <xsl:call-template name="basename">
                <xsl:with-param name="in" select="$fileName"/>
            </xsl:call-template>
        </xsl:variable>
        <!-- get the width and height values given in the object element -->
        <xsl:variable name="width">
            <xsl:call-template name="returnAttr">
                <xsl:with-param name="element" select="$object"/>
                <xsl:with-param name="key" select="'width'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="wPC" select="substring-before($width,'%')"/>
        <xsl:variable name="height">
            <xsl:call-template name="returnAttr">
                <xsl:with-param name="element" select="$object"/>
                <xsl:with-param name="key" select="'height'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="hPC" select="substring-before($height,'%')"/>
        <!-- get the final required width/height. If the user has given explicit sizes, 
        take them without change; otherwise use the percentage value based on the
        basic window size values -->
        <xsl:variable name="w">
            <xsl:choose>
                <xsl:when test="string-length($wPC) = 0"><xsl:value-of select="$width"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="($BasicWidth * $wPC) div $hundred"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="h">
            <xsl:choose>
                <xsl:when test="string-length($hPC) = 0"><xsl:value-of select="$height"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="($BasicHeight * $hPC) div $hundred"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!-- get now the internal coordinate size of the svg file, this is in its viewBox attribute -->
        <xsl:variable name="viewBox">
            <xsl:value-of select="document($fileName)/svg/@viewBox"/>
        </xsl:variable>
        <xsl:variable name="tmp" select="substring-after(substring-after($viewBox,' '),' ')"/>
        <xsl:variable name="s" select="substring-before($tmp,' ')"/>
        <xsl:variable name="m" select="substring-after($tmp,' ')"/>
        <!-- The goal of the calculations: first try to force the size into the available width. Then
        look at the height if it is o.k., if not, a second shrink is done in y -->
        <!-- First shoot at x and y, by shriking horizontally: -->
        <xsl:variable name="x">
            <xsl:choose>
                <xsl:when test="$s &lt; $w">
                    <xsl:value-of select="$s"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$w"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="y">
            <xsl:value-of select="$x * ($m div $s)"/>
        </xsl:variable>
        <!-- Get the final values by looking at the vertical direction. The structure of XSLT and
        the variable binding forces me to duplicate a logical if-then-else structure -->
        <xsl:variable name="yFinal">
            <xsl:choose>
                <xsl:when test="$y &gt; $h">
                    <xsl:value-of select="$h"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$y"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="xFinal">
            <xsl:choose>
                <xsl:when test="$y &gt; $h">
                    <xsl:value-of select="$x * ($yFinal div $y)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$x"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!-- return everything in one variable -->
        <xsl:value-of select="concat('width:',round($xFinal),';','height:',round($yFinal))"/>
    </xsl:template>
    <!-- ================================================================== -->
    <!--                        Copying SVG elements                        -->
    <!-- ================================================================== -->
    <!-- 
        Recursive function to manage SVG elements. The function also manages
        the xlink pattern changes on the fly.
    -->
    <xsl:template name="svg">
        <xsl:param name="element"/>
        <xsl:param name="fromURL"/>
        <xsl:param name="toURL"/>
        <xsl:variable name="nsuriB" select="namespace-uri($element)"/>
        <xsl:variable name="nsuri">
        	<xsl:choose>
        	    <xsl:when test="$nsuriB = ''">http://www.w3.org/2000/svg</xsl:when>
        	    <xsl:otherwise><xsl:value-of select="$nsuriB"/></xsl:otherwise>	
        	</xsl:choose>
        </xsl:variable>
        <xsl:variable name="name" select="normalize-space(local-name($element))"/>
        <xsl:choose>
            <xsl:when test="string-length($name)!=0">
                <!-- Most of the content is in the usual namespace,
                     but some elements might be in their own, eg, my own extensions, or the Adobe extensions.
                     I prefer not to touch the metadata and the foreignObject part and simply copy it recursively; 
                     all others are copied recursively through this method, with the possible xlink:href tags modified on the fly.
                -->
                <xsl:choose>
                    <xsl:when test="$name = 'metadata' or $name = 'foreignObject'">
                        <xsl:element name="{$name}" namespace="http://www.w3.org/2000/svg">
                            <xsl:copy-of select="$element/*|$element/@*"/>
                        </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:element name="{$name}" namespace="{$nsuri}">
                            <!-- 
		                        gather and copy the attributes. If necessary, the change in 
		                        relative URL takes place here
	                        -->
                            <xsl:for-each select="$element/@*">
                                <xsl:copy/>
                            </xsl:for-each>
                            <!-- 
                                do the conversion on the xlink:href attribute, if present
                            -->
                            <xsl:if test="$element/@xlink:href">
                                <xsl:if test="starts-with($element/@xlink:href,$fromURL)">
                                    <xsl:attribute name="xlink:href">
                                        <xsl:value-of select="concat($toURL,substring-after($element/@xlink:href,$fromURL))"/>
                                    </xsl:attribute>
                                </xsl:if>
                            </xsl:if>
                            <!-- 
                               Elements either have text or element children ...
                               Handle them recursively 
                            -->
                            <xsl:for-each select="$element/*|$element/text()">
                                <xsl:call-template name="svg">
                                    <xsl:with-param name="element" select="."/>
                                    <xsl:with-param name="fromURL" select="$fromURL"/>
                                    <xsl:with-param name="toURL" select="$toURL"/>
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:element>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <!-- it is a text element which must be copied -->
                <xsl:copy/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!-- ================================================================== -->
    <!--            Managing author/URL pairs to generate signature         -->
    <!-- ================================================================== -->
    <xsl:template name="sigList">
        <xsl:param name="aFirst"/>
        <xsl:param name="uFirst"/>
        <xsl:param name="aRest"/>
        <xsl:param name="uRest"/>
        <xsl:param name="target"/>
        <xsl:if test="string-length($aFirst) != 0">
            <xsl:choose>
                <xsl:when test="string-length($uFirst) != 0">
                    <xsl:choose>
                        <xsl:when test="$target = 'html'">
                            <a href="{$uFirst}"><xsl:value-of select="$aFirst"/></a>
                        </xsl:when>
                        <xsl:otherwise>
                            <a xmlns="http://www.w3.org/2000/svg" xlink:href="{$uFirst}"><xsl:value-of select="$aFirst"/></a>
                        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="string-length($aRest) != 0">
                        <xsl:text>, </xsl:text>
                        <xsl:call-template name="sigList">
                            <xsl:with-param name="aFirst" select="substring-before($aRest,',')"/>
                            <xsl:with-param name="uFirst" select="normalize-space(substring-before($uRest,','))"/>
                            <xsl:with-param name="aRest" select="substring-after($aRest,',')"/>
                            <xsl:with-param name="uRest" select="normalize-space(substring-after($uRest,','))"/>
                            <xsl:with-param name="target" select="$target"/>
                        </xsl:call-template>                        
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$aFirst"/>
                    <xsl:if test="string-length($aRest) != 0"><xsl:text>, </xsl:text><xsl:value-of select="$aRest"/></xsl:if>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </xsl:template>
    <!-- ================================================================== -->
    <!--                          Boilerplates                              -->
    <!-- ================================================================== -->
    <!-- The general catch alls; the head is taken separately to be swallowed... -->
    <xsl:template match="text()" priority="1">
        <xsl:value-of disable-output-escaping="no" select="."/>
    </xsl:template>
    <!-- head contents are handled explicitly -->
    <xsl:template match="x:html/x:head"/>
    <!-- h1-s are handled separately... -->
    <xsl:template match="/x:html/x:body/x:div/x:h1"/>
</xsl:stylesheet>
