<?xml version='1.0'?>
<!DOCTYPE doc SYSTEM "../../../../lib/xml/xsl.dtd" >
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:x="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="x">
 <!-- Convert a Corpus Thomisticum Latin file into one with true divs,
       replacing existing divs with h2/h3 -->
 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>
 
 <xsl:template match="x:body">
  <xsl:copy>
   <xsl:apply-templates select="x:a|x:div[@class='tres' or @class='uno' or @class='dos']|x:div[@class='centro'][1]"/>
  <xsl:for-each-group select="x:p|x:div[not(@class='tres' or @class='uno' or @class='dos' or @class='centro')]" group-starting-with="x:div[@class='D']">
   <xsl:variable name="n" select="substring-after(.,'Quaestio ')"/>
  <div class="q" id="q{$n}">
   <h2><xsl:apply-templates/></h2>
    <xsl:apply-templates select="current-group()[position()>1]"/>   
  </div>
  </xsl:for-each-group>
   <xsl:apply-templates select="x:div[@class='centro'][2]"/>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>
