<?xml version="1.0"?>
<xsl:stylesheet   version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 
     This stylesheet processes an XML glossary and outputs terms in alphabetical order.
     It is tied to the DTD, so changes to the DTD need to be reflected here. The DTD
     model assumes that a repeatable DefinitionSection consists of these elements:
             Concept*, Definition, Usage?, Source?, Synonym*, RelatedTerm*
     CSS (defined within this XSLT) is used to control the visual presentation.
     The stylesheet also generates 3 search links for each term (Google and WordNet.) 
     This could easily be extended to search other sources.
     Glossary XSLT, DTD, and example by Ken Sall, SiloSmashers (ksall@silosmashers.com).   
-->
<xsl:output method="html" indent="yes" />

<xsl:variable name="PageTitle">Strawman Glossary Example</xsl:variable>

<xsl:template match="/">
   <html>  
     <head>
       <title><xsl:value-of select="$PageTitle" /></title>
       <style type="text/css">
       body       { margin:3em; font-family: Arial; }
       .term      {border: thin #cccccc solid; text-indent:1em; color: blue; font-weight:bold; font-size:125%;}
       .acronym   {text-indent:3em; color: black; }
       .normal    {text-indent:3em; color: black; }
       .nested    {text-indent:5em; color: black; }
       </style>
     </head>
     <body>
       <h1 align="center"><xsl:value-of select="$PageTitle" /></h1>

       <xsl:apply-templates select="/Glossary/Term/Name" >
         <xsl:sort order="ascending" select="." />  
       </xsl:apply-templates> 

     <hr /><p style="font-size:75%; text-align:center">Example by <a href="mailto:ksall@silosmashers.com">Ken Sall, SiloSmashers</a>.</p>
     </body>
   </html>
</xsl:template>

<xsl:template match="Name">
   <p class="term"><xsl:value-of select="." /></p>
   <xsl:if test="../ExpandedAcronym">
     <p><span class="acronym">Acronym Expansion: <b><xsl:value-of select="../ExpandedAcronym" /> (<xsl:value-of select="../Acronym" />)</b></span></p>
   </xsl:if>
   
   <xsl:apply-templates select="../DefinitionSection" />  
   <!-- Generate search links, not in input XML. -->
   <xsl:call-template name="SetSearchLinks"> 
     <xsl:with-param name="TermName" select="."/>
   </xsl:call-template>
</xsl:template> 

<xsl:template match="DefinitionSection">
<!-- DTD Model = Concept*, Definition, Usage?, Source?, Synonym*, RelatedTerm* -->
   <p class="normal">
   <b>Concept(s): </b>
   <xsl:for-each select="Concept">
     <span class="normal"><xsl:value-of select="." /></span>
     <xsl:if test="position() != last()">
       <span class="normal">; </span>
     </xsl:if>
   </xsl:for-each>
   <br />
   <i>Definition: </i><span class="normal"><xsl:value-of select="Definition" /></span>
   <xsl:if test="Source">
     <br />  
     <i>Source: </i><span class="normal"><xsl:value-of select="Source" /></span>
   </xsl:if>     
   <xsl:if test="Usage">
     <br />
     <i>Usage Example: </i><span class="normal"><xsl:value-of select="Usage" /></span>
   </xsl:if>     
   
   <xsl:if test="Synonym">
      <br /><i>Synonym(s): </i>
      <xsl:for-each select="Synonym">
           <span class="normal"><xsl:value-of select="." /></span>
           <xsl:if test="position() != last()">
	      <span class="normal">; </span>
           </xsl:if>
      </xsl:for-each>
   </xsl:if>
   <xsl:if test="RelatedTerm">
      <br /><i>RelatedTerm(s): </i>
      <xsl:for-each select="RelatedTerm">
           <span class="normal"><xsl:value-of select="." /></span>
           <xsl:if test="position() != last()">
	      <span class="normal">; </span>
           </xsl:if>
      </xsl:for-each>
   </xsl:if>
   </p>
</xsl:template> 

<!-- All search link info is defined in SetSearchLinks. -->
<xsl:template name="SetSearchLinks">
   <xsl:param name="TermName" />
   <xsl:variable name="WordNet">http://www.cogsci.princeton.edu/cgi-bin/webwn2.0?stage=1&amp;word=</xsl:variable>
   <xsl:variable name="GoogleDefine">http://www.google.com/search?hl=en&amp;q=define%3A</xsl:variable>
   <xsl:variable name="Google">http://www.google.com/search?hl=en&amp;q=</xsl:variable>
   
   <p class="normal">
     <i>Generated Searches for <xsl:value-of select="$TermName" />: </i> 
     <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="concat($GoogleDefine, $TermName)" /></xsl:attribute>Google Define</xsl:element><xsl:text>;  </xsl:text>
     <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="concat($WordNet, $TermName)" /></xsl:attribute>WordNet</xsl:element><xsl:text>;  </xsl:text>   
     <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="concat($Google, $TermName)" /></xsl:attribute>Google Search</xsl:element><xsl:text>.</xsl:text>
   </p>
</xsl:template> 

</xsl:stylesheet>
