<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes"
    doctype-public="-//W3C//DTD SVG 1.0//EN"
    doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg-19991203.dtd"
              version="1.0"
              encoding="ISO-8859-1" />
  <xsl:strip-space elements="*"/>

  <!--================================================================-->
  <!-- Root Element Template                                          -->
  <!-- This template specifies what creates the root element of the   -->
  <!-- result tree.  In this case, it tells the XSL processor to      -->
  <!-- start with the <sonnet> element.                               -->
  <!--================================================================-->

  <xsl:template match="/">
    <xsl:apply-templates select="sonnet"/>
  </xsl:template>

  <!--================================================================-->
  <!-- <sonnet> template                                              -->
  <!--                                                                -->
  <!-- This template creates the entire SVG document.  It simply      -->
  <!-- writes the various parts of the sonnet, color coding the lines -->
  <!-- appropriately.  We do this with various <text> elements, so    -->
  <!-- the stylesheet isn't that complicated.  To keep things simple, -->
  <!-- we've hardcoded the font sizes and the starting positions of   -->
  <!-- each line.  (All sonnets have 14 lines, so that's a reasonable -->
  <!-- restriction in this case.)                                     -->
  <!--================================================================-->

  <xsl:template match="sonnet">
    <svg height="400" width="450">

  <!--================================================================-->
  <!-- Write out the <title> element.  This is written in 24-point    -->
  <!-- type.                                                          -->
  <!--================================================================-->

      <text style="font-size:24" x="20" y="20">
        <xsl:value-of select="title"/>
      </text>

  <!--================================================================-->
  <!-- Now we'll write out the author information.  We extract the    -->
  <!-- various parts of the description from the XML document.  The   -->
  <!-- only complication here is that we print the author's birth     -->
  <!-- year, death year, and nationality in italics.  To do this, we  -->
  <!-- use an SVG <tspan> element.                                    -->
  <!--================================================================-->

      <text style="font-family:Arial; font-size:18;" x="20" y="40">Author: 
        <xsl:value-of select="author/first-name"/> 
        <xsl:text> </xsl:text>
        <xsl:value-of select="author/last-name"/>
        <xsl:text> (</xsl:text>
        <tspan style="font-style:italic">
          <xsl:value-of select="author/nationality"/>, 
          <xsl:value-of select="author/year-of-birth"/>-<xsl:value-of select="author/year-of-death"/>
        </tspan>
        <xsl:text>)</xsl:text>
      </text>

  <!--================================================================-->
  <!-- Now that we've output the author information, we'll write the  -->
  <!-- lines of the sonnet.  We use the <g> (group) tag to set the    -->
  <!-- font-size globally.                                            -->
  <!--================================================================-->

      <g style="font-size:14">
        <xsl:apply-templates select="//line" />
      </g>
    </svg>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the first line of the sonnet.  In our XML-HTML    -->
  <!-- stylesheet, we used a single template for the first and third  -->
  <!-- lines, the second and fourth lines, etc.  We can't do that     -->
  <!-- here because the y coordinate values change for each line.     -->
  <!--                                                                -->
  <!-- Each of these templates output a letter indicating the rhyme   -->
  <!-- scheme, and then it outputs the line of the sonnet.  It also   -->
  <!-- sets the color appropriately.                                  -->
  <!--                                                                -->
  <!-- As with our XML-HTML stylesheet, we'd have to change things if -->
  <!-- we wanted to handle Petrarchan sonnets or other forms.         -->
  <!--================================================================-->

  <xsl:template match="line[1]">
    <text x="20" y="60" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>A</xsl:text>
    </text>
    <text x="40" y="60" style="fill:green">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the second line of the sonnet.                    -->
  <!--================================================================-->

  <xsl:template match="line[2]">
    <text x="20" y="78" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:purple">
      <xsl:text>B</xsl:text>
    </text>
    <text x="40" y="78" style="fill:purple">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the third line of the sonnet.                     -->
  <!--================================================================-->

  <xsl:template match="line[3]">
    <text x="20" y="96" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>A</xsl:text>
    </text>
    <text x="40" y="96" style="fill:green">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the fourth line of the sonnet.                    -->
  <!--================================================================-->

  <xsl:template match="line[4]">
    <text x="20" y="114" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:purple">
      <xsl:text>B</xsl:text>
    </text>
    <text x="40" y="114" style="fill:purple">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the fifth line of the sonnet.                     -->
  <!--================================================================-->

  <xsl:template match="line[5]">
    <text x="20" y="132" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>C</xsl:text>
    </text>
    <text x="40" y="132" style="fill:green">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the sixth line of the sonnet.                     -->
  <!--================================================================-->

  <xsl:template match="line[6]">
    <text x="20" y="150" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:purple">
      <xsl:text>D</xsl:text>
    </text>
    <text x="40" y="150" style="fill:purple">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the seventh line of the sonnet.                   -->
  <!--================================================================-->

  <xsl:template match="line[7]">
    <text x="20" y="168" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>C</xsl:text>
    </text>
    <text x="40" y="168" style="fill:green">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the eighth line of the sonnet.                    -->
  <!--================================================================-->

  <xsl:template match="line[8]">
    <text x="20" y="186" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:purple">
      <xsl:text>D</xsl:text>
    </text>
    <text x="40" y="186" style="fill:purple">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the ninth line of the sonnet.                     -->
  <!--================================================================-->

  <xsl:template match="line[9]">
    <text x="20" y="204" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>E</xsl:text>
    </text>
    <text x="40" y="204" style="fill:green">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the tenth line of the sonnet.                     -->
  <!--================================================================-->

  <xsl:template match="line[10]">
    <text x="20" y="222" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:purple">
      <xsl:text>F</xsl:text>
    </text>
    <text x="40" y="222" style="fill:purple">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the eleventh line of the sonnet.                  -->
  <!--================================================================-->

  <xsl:template match="line[11]">
    <text x="20" y="240" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>E</xsl:text>
    </text>
    <text x="40" y="240" style="fill:green">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the twelfth line of the sonnet.                   -->
  <!--================================================================-->

  <xsl:template match="line[12]">
    <text x="20" y="258" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:purple">
      <xsl:text>F</xsl:text>
    </text>
    <text x="40" y="258" style="fill:purple">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the thirteenth line of the sonnet.                -->
  <!-- G Wilcock 04/12/02: change colour of last two lines to blue.   -->
  <!--================================================================-->

  <xsl:template match="line[13]">
    <text x="20" y="276" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>G</xsl:text>
    </text>
    <text x="40" y="276" style="fill:blue">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

  <!--================================================================-->
  <!-- Template for the fourteenth line of the sonnet.                -->
  <!-- G Wilcock 04/12/02: change colour of last two lines to blue.   -->
  <!--================================================================-->

  <xsl:template match="line[14]">
    <text x="20" y="294" 
          style="font-family:Arial; font-weight:bold; 
                 font-style:italic; fill:green">
      <xsl:text>G</xsl:text>
    </text>
    <text x="40" y="294" style="fill:blue">
      <xsl:value-of select="." />
    </text>
  </xsl:template>

</xsl:stylesheet>


