<!-- Add sectioning around tables -->

<xsl:transform version="1.0"
	       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="xml" encoding='utf-8' indent='yes'/>
  <xsl:preserve-space elements="*"/>
  
  <xsl:template match="p[table/tbody/tr/th/@id]">
    <xsl:apply-templates select="table"/>
  </xsl:template>
  
  <xsl:template match="table[tbody/tr/th/@id]">
    <div5 id="{tbody/tr/th/@id}">
      <head><xsl:value-of select=".//th[@id]/text()"/></head>
      <xsl:copy>
	<xsl:apply-templates select="@*|node()" mode="copyex"/>
      </xsl:copy>
    </div5>
  </xsl:template>
  
  <xsl:template match="tr[th/@id]" mode="copyex"/>
  <xsl:template match="@*|node()" mode="copyex">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" mode="copyex"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:transform>


