<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
     xmlns:html="http://www.w3.org/TR/REC-html40" 
     xmlns:xsch="http://www.w3.org/1999/XMLSchema" 
                 version="1.0" >

<!-- HTML Glossary to XML Schema 
-->

<xsl:template match="body">
 <xsch:schema>
  <xsl:apply-templates select="*|@*"/>
 </xsch:schema>
</xsl:template>

<xsl:template match="body/p[b]|BODY/P[B]">
 <xsl:variable name="word">
  <xsl:value-of select="b|B"/> 
 </xsl:variable>
 <xsl:variable name="word2"
   select='translate(normalize-space($word), " :", "_")'/>

 <xsl:variable name="parag">
  <xsl:value-of select="normalize-space(text())"/> 
 </xsl:variable>

 <xsl:choose>
  <!-- Content: (xsl:when+, xsl:otherwise?) -->

 <xsl:when
  test = 'starts-with( $parag, "a ") or 
  starts-with( $parag, "the ")' >
   <!-- boolean starts-with(string, string) 
-->
  <!-- Content: template -->
  <xsl:element name="xsch:element">
   <xsl:attribute name='name'>
    <xsl:value-of select="$word2"/>
   </xsl:attribute>
   <xsl:element name="documentation">
    <xsl:value-of select="$parag"/> 
   </xsl:element>
  </xsl:element>
 </xsl:when>
  <xsl:otherwise>
   <xsl:element name="adjective">
    <xsl:attribute name='name'>
     <xsl:value-of select="$word2"/>
    </xsl:attribute>
    <xsl:element name="definition">
     <xsl:value-of select="$parag"/> 
    </xsl:element>
   </xsl:element>
  </xsl:otherwise> 

 </xsl:choose> 


</xsl:template>

<!-- This the simplest identity function 
     Without the <xsl:copy> statement, tags wouldn't be reproduced -->
 <xsl:template match="@*|*">
  <xsl:copy>
    <xsl:apply-templates select="*|@*"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
