<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:html="http://www.w3.org/HTML/1998/html4"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    exclude-result-prefixes="#default" >

<!-- **************************************************
     XSLT stylesheet to convert upCast v3 XML (generic DTD) documents to 
                     upCast v4 XML (upCast DTD) documents for more suitable
                     processing with downCast
                     
     DISCLAIMER:
       This stylesheet is provided AS IS with no warranty.
       Use completely at your own risk!
                       
     ******

     Author :  Christian Roth <roth@infinity-loop.de>
     Version:  1.0r2
     Date   :  2003-10-10
     
     ******
     
     
     ______
     Notes:
     ______
     
     The variable "stylesheet-url" holds the URL for the
       default .css stylesheet you need to create to
       style your document. When empty (=''), no stylesheet
       PI is included in the resulting document.
       
     In upCast 3.x, set:
       * DTD type: DTD
       * Write to file: checked
       * Namespace for upCast elements: (leave empty, otherwise you need to adjust the
                                         match expressions and namespace declarations
                                         in this stylesheet)
       * 'kind' naming convention: XML 1.0
     
     ***************************************************
-->

<!-- The stylesheet we should link to. If empty, no stylesheet PI is written. -->
<xsl:variable name="stylesheet-url">default.css</xsl:variable>


<!-- Output method: XML -->
<xsl:output method="xml" 
            indent="yes" 
            encoding="UTF-8"
            omit-xml-declaration="no"
            doctype-public="-//infinity-loop//DTD upCast 4.0//EN" 
            doctype-system="http://www.infinity-loop.de/DTD/upcast/4.0/upcast.dtd"
/>

<xsl:strip-space elements="*"/>


<!-- 
 **********
 some useful templates 
 ********** 
-->

<!-- copy all attributes -->
<xsl:template name="copy-all-attributes">
  <xsl:for-each select="@*">
    <xsl:copy />
  </xsl:for-each>
</xsl:template>

<!-- copy current node and all of its sub nodes -->
<xsl:template name="copy-node-deep">
  <xsl:element name="{name()}">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>

<!-- 
 **********
 The "real" document elements 
 ********** 
-->

<!-- The document element -->
<xsl:template match="document">
  <xsl:if test="not( $stylesheet-url = '' )">
    <xsl:processing-instruction name="xml-stylesheet">type="text/css" href="<xsl:value-of select="$stylesheet-url" />"</xsl:processing-instruction>
  </xsl:if>  
  <document xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:html="http://www.w3.org/HTML/1998/html4">
    <xsl:apply-templates />
  </document>
</xsl:template>


<!-- documentinfo -->
<xsl:template match="documentinfo">
  <documentinfo>
    <xsl:apply-templates/>
  </documentinfo>
</xsl:template>


<!-- property -->
<xsl:template match="property">
  <xsl:element name="property">
    <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
    <xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>
    <xsl:choose>
      <xsl:when test="@name='title'"><xsl:attribute name="type"><xsl:text>text</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='author'"><xsl:attribute name="type"><xsl:text>text</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='operator'"><xsl:attribute name="type"><xsl:text>text</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='creationTime'"><xsl:attribute name="type"><xsl:text>date</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='revisionTime'"><xsl:attribute name="type"><xsl:text>date</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='editingMinutes'"><xsl:attribute name="type"><xsl:text>integer</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='numberOfPages'"><xsl:attribute name="type"><xsl:text>integer</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='numberOfWords'"><xsl:attribute name="type"><xsl:text>integer</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='numberOfChars'"><xsl:attribute name="type"><xsl:text>integer</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='company'"><xsl:attribute name="type"><xsl:text>text</xsl:text></xsl:attribute></xsl:when>
      <xsl:when test="@name='numberOfCharsWS'"><xsl:attribute name="type"><xsl:text>integer</xsl:text></xsl:attribute></xsl:when>
      <!-- ... add cases as appropriate. -->
      <xsl:otherwise><xsl:attribute name="type"><xsl:text>text</xsl:text></xsl:attribute></xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>


<!-- part -->
<xsl:template match="part">
  <part>
    <xsl:apply-templates />
  </part>
</xsl:template>


<!-- section -->
<xsl:template match="section">
  <section>
    <xsl:attribute name="level">
      <xsl:value-of select="@level" />
    </xsl:attribute>
    <xsl:apply-templates />
  </section>
</xsl:template>


<!-- heading -->
<xsl:template match="heading">
  <heading>
    <xsl:attribute name="level">
      <xsl:value-of select="@level" />
    </xsl:attribute>
    <xsl:attribute name="class">
      <xsl:value-of select="translate( @kind, '-', '&#160;')" />
    </xsl:attribute>
    <xsl:apply-templates />
  </heading>
</xsl:template>

<!-- par -->
<xsl:template match="par">
  <par>
    <xsl:attribute name="class">
      <xsl:value-of select="@kind" />
    </xsl:attribute>
    <xsl:attribute name="style">
      <xsl:if test="@halign">
        <xsl:text>text-align: </xsl:text>
        <xsl:value-of select="@halign"/>
        <xsl:text>;</xsl:text>
      </xsl:if>
    </xsl:attribute>
    <xsl:apply-templates />
  </par>
</xsl:template>


<!-- inline -->
<xsl:template match="inline">
  <inline>
    <xsl:choose>

      <!-- font -->
      <xsl:when test="@kind='font'">
        <xsl:attribute name="style">
          <xsl:text>font-family: &quot;</xsl:text>
          <xsl:value-of select="@value" />
          <xsl:text>&quot;;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
  
      <!-- shiftup -->
      <xsl:when test="@kind='shiftup'">
        <xsl:attribute name="style">
          <xsl:text>vertical-align: </xsl:text>
          <xsl:value-of select="@value" />
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
  
      <!-- shiftdown -->
      <xsl:when test="@kind='shiftdown'">
        <xsl:attribute name="style">
          <xsl:text>vertical-align: -</xsl:text>
          <xsl:value-of select="@value" />
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
  
      <!-- subscript -->
      <xsl:when test="@kind='subscript'">
        <xsl:attribute name="style">
          <xsl:text>vertical-align: sub;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
  
      <!-- superscript -->
      <xsl:when test="@kind='superscript'">
        <xsl:attribute name="style">
          <xsl:text>vertical-align: super;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
  
      <!-- fontsize -->
      <xsl:when test="@kind='fontsize'">
        <xsl:attribute name="style">
          <xsl:text>font-size: </xsl:text>
          <xsl:value-of select="@value" />
          <xsl:text>;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
  
      <!-- smallcaps -->
      <xsl:when test="@kind='smallcaps'">
        <xsl:attribute name="style">
          <xsl:text>font-variant: small-caps;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>

      <!-- allcaps -->
      <xsl:when test="@kind='allcaps'">
        <xsl:attribute name="style">
          <xsl:text>font-variant: uppercase;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>

      <!-- textcolor: DOES NOT WORK since it is a number referring to the corresponding CSS -->
      <xsl:when test="@kind='textcolor'">
        <xsl:attribute name="style">
          <xsl:text>color: inherit;</xsl:text> <!-- best we can do here easily... -->
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when> 
  

      <!-- bold -->
      <xsl:when test="@kind='bold'">
        <xsl:attribute name="style">
          <xsl:text>font-weight: bold;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>

      <!-- italic -->
      <xsl:when test="@kind='italic'">
        <xsl:attribute name="style">
          <xsl:text>font-style: italic;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>

      <!-- underline, thickunderline -->
      <xsl:when test="@kind='underline|thickunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: solid; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- wordunderline -->
      <xsl:when test="@kind='wordunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: solid; text-underline-mode: skip-white-space;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- doubleunderline -->
      <xsl:when test="@kind='doubleunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: double; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- dotunderline -->
      <xsl:when test="@kind='dotunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: dotted; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- dashunderline -->
      <xsl:when test="@kind='dashunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: dashed; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- dotdashunderline -->
      <xsl:when test="@kind='dotdashunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: dot-dash; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- dotdotdashunderline -->
      <xsl:when test="@kind='dotdotdashunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: dot-dot-dash; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      <!-- waveunderline -->
      <xsl:when test="@kind='waveunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: wave; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>


      <!-- strikethrough -->
      <xsl:when test="@kind='strikethrough'">
        <xsl:attribute name="style">
          <xsl:text>text-decoration: line-through; text-line-through-style: solid;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>

      <!-- doublestrikethrough -->
      <xsl:when test="@kind='doublestrikethrough'">
        <xsl:attribute name="style">
          <xsl:text>text-decoration: line-through; text-line-through-style: double;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>

      <!-- doubleunderline -->
      <xsl:when test="@kind='doubleunderline'">
        <xsl:attribute name="style">
          <xsl:text>text-underline-style: double; text-underline-mode: continuous;</xsl:text>
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      
      <!-- shadow, outline, emboss, engrave -->
      <xsl:when test="@kind='shadow|outline|emboss|engrave'">
        <xsl:attribute name="style">
          <xsl:text>color: grey;</xsl:text> <!-- we make it grey as a best approximation effort -->
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:when>
      

      <!-- user-defined character styles -->
      <xsl:otherwise>
        <xsl:attribute name="class">
          <xsl:value-of select="@kind" />
        </xsl:attribute>
        <xsl:apply-templates />
      </xsl:otherwise>
    </xsl:choose>
  </inline>
</xsl:template>



<!-- url -->
<xsl:template match="url">
  <xsl:element name="link">
    <xsl:attribute name="xlink:type"><xsl:text>simple</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:show"><xsl:text>replace</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:actuate"><xsl:text>onRequest</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:href"><xsl:value-of select="@name" /></xsl:attribute>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- reference -->
<xsl:template match="reference">
  <xsl:element name="reference">
    <xsl:attribute name="xlink:type"><xsl:text>simple</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:show"><xsl:text>other</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:actuate"><xsl:text>onLoad</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:href"><xsl:value-of select="@name" /></xsl:attribute>
    
    <!-- the default presentation: -->
    <xsl:attribute name="embed"><xsl:text>number</xsl:text></xsl:attribute>
    <xsl:attribute name="style"><xsl:text>\-ilx-reference-presentation-type: number;</xsl:text></xsl:attribute>

    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- hidden -->
<xsl:template match="hidden">
  <hidden>
    <xsl:apply-templates />
  </hidden>
</xsl:template>


<!-- 
************
FORMS
************
-->

<xsl:template match="formtext">
  <formtext>
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </formtext>
</xsl:template>

<xsl:template match="formcheckbox">
  <formcheckbox>
    <xsl:call-template name="copy-all-attributes" />
    <!-- this is now an empty element -->
  </formcheckbox>
</xsl:template>

<xsl:template match="formdropdown">
  <formdropdown>
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates select="choiceList" />
  </formdropdown>
</xsl:template>

<xsl:template match="choiceList">
  <choiceList>
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates select="choice" />
  </choiceList>
</xsl:template>

<xsl:template match="choice">
  <choice>
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </choice>
</xsl:template>

<!-- 
************
TABLES
************
-->

<!-- *** HTML *** -->

<!-- table -->
<xsl:template match="table">
  <html:table style="width: 100%; border: 1px solid black; margin-right: auto; border-spacing: 0.0pt 0.0pt; border-collapse: collapse;">
    <xsl:apply-templates />
  </html:table>
</xsl:template>

<!-- thead -->
<xsl:template match="thead">
  <html:thead>
    <xsl:apply-templates />
  </html:thead>
</xsl:template>

<!-- tbody -->
<xsl:template match="tbody">
  <html:tbody>
    <xsl:apply-templates />
  </html:tbody>
</xsl:template>

<!-- row -->
<xsl:template match="row">
  <html:tr>
    <xsl:apply-templates />
  </html:tr>
</xsl:template>

<!-- cell -->
<xsl:template match="cell">
  <xsl:element name="html:td">
    <xsl:if test="@colspan">
      <xsl:attribute name="colspan"><xsl:value-of select="@colspan" /></xsl:attribute>
    </xsl:if>
    <xsl:if test="@rowspan">
      <xsl:attribute name="rowspan"><xsl:value-of select="@rowspan" /></xsl:attribute>
    </xsl:if>
    <xsl:attribute name="style">
      <xsl:if test="@width">
        <xsl:text>width: </xsl:text><xsl:value-of select="@width"/><xsl:text>px; </xsl:text>
      </xsl:if>
      <xsl:if test="@cellbgcolor">
        <xsl:text>background-color: </xsl:text><xsl:value-of select="@cellbgcolor"/><xsl:text>;</xsl:text>
      </xsl:if>
      <xsl:if test="@valign">
        <xsl:text>vertical-align: </xsl:text>
        <xsl:choose>
          <xsl:when test="@valign = 'center'">
            <xsl:text>middle</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@valign"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>;</xsl:text>
      </xsl:if>
    </xsl:attribute>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- 
************
LISTS 
************
-->

<!-- list -->
<xsl:template match="list">
  <list>
    <xsl:call-template name="copy-all-attributes" />
    <xsl:attribute name="listtype">
      <xsl:choose>
        <xsl:when test="@listtype='ordinal'"><xsl:text>decimal</xsl:text></xsl:when>
        <xsl:when test="@listtype='roman-uppercase'"><xsl:text>upper-roman</xsl:text></xsl:when>
        <xsl:when test="@listtype='roman-lowercase'"><xsl:text>lower-roman</xsl:text></xsl:when>
        <xsl:when test="@listtype='alphabetic-uppercase'"><xsl:text>upper-alpha</xsl:text></xsl:when>
        <xsl:when test="@listtype='alphabetic-lowercase'"><xsl:text>lower-alpha</xsl:text></xsl:when>
        <xsl:otherwise><xsl:value-of select="@listtype"/></xsl:otherwise>        
      </xsl:choose>
    </xsl:attribute>
    <xsl:attribute name="style">
      <xsl:text>list-style-type: </xsl:text>
      <xsl:choose>
        <xsl:when test="@listtype='ordinal'"><xsl:text>decimal</xsl:text></xsl:when>
        <xsl:when test="@listtype='roman-uppercase'"><xsl:text>upper-roman</xsl:text></xsl:when>
        <xsl:when test="@listtype='roman-lowercase'"><xsl:text>lower-roman</xsl:text></xsl:when>
        <xsl:when test="@listtype='alphabetic-uppercase'"><xsl:text>upper-alpha</xsl:text></xsl:when>
        <xsl:when test="@listtype='alphabetic-lowercase'"><xsl:text>lower-alpha</xsl:text></xsl:when>
        <xsl:otherwise><xsl:value-of select="@listtype"/></xsl:otherwise>        
      </xsl:choose>
      <xsl:text>; </xsl:text>
      <xsl:text>margin-left: 0.5in; \-ilx-marker-format: &quot;%</xsl:text>
      <xsl:value-of select="count(ancestor::list)"/>
      <xsl:text>.&quot;; \-ilx-marker-align: left; \-ilx-marker-follow: tab; \-ilx-marker-offset: -360tw;</xsl:text>
    </xsl:attribute>
    <xsl:apply-templates />
  </list>
</xsl:template>

<!-- item -->
<xsl:template match="item">
  <xsl:element name="item">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>



<!-- image -->
<xsl:template match="image">
  <xsl:element name="image">
    <xsl:attribute name="xlink:type"><xsl:text>simple</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:actuate"><xsl:text>onLoad</xsl:text></xsl:attribute>
    <xsl:attribute name="xlink:href"><xsl:value-of select="@src" /></xsl:attribute>
    <xsl:attribute name="xlink:show"><xsl:text>embed</xsl:text></xsl:attribute>
    <xsl:choose>
      <xsl:when test="string-length(@height)=0">
        <xsl:attribute name="style">
          <xsl:text>border-style: none; </xsl:text>
          <xsl:text>\-ilx-image-source: reference;</xsl:text>
        </xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="style">
          <xsl:text>border-style: none; </xsl:text>
          <xsl:text>width: </xsl:text><xsl:value-of select="@width"/><xsl:text>px; </xsl:text>
          <xsl:text>height: </xsl:text><xsl:value-of select="@height"/><xsl:text>px; </xsl:text>
          <xsl:text>\-ilx-image-source: embed;</xsl:text>
        </xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- subdoc -->
<xsl:template match="subdoc">
  <xsl:element name="subdoc">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- footnote -->
<xsl:template match="footnote">
  <xsl:element name="footnote">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- textbox -->
<xsl:template match="textbox">
  <xsl:element name="textbox">
    <xsl:attribute name="style">
      <xsl:text>width: 100%; float: left; background-color: white; borders: 0.15pt black solid; padding-right: 2.5mm; z-index: 1; padding-top: 1.3mm; padding-bottom: 1.3mm; padding-left: 2.5mm; </xsl:text>
    </xsl:attribute>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- annotation -->
<xsl:template match="annotation">
  <xsl:element name="annotation">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- inscontent -->
<xsl:template match="inscontent">
  <xsl:element name="inserted">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- delcontent -->
<xsl:template match="delcontent">
  <xsl:element name="deleted">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- gentext -->
<xsl:template match="gentext">
  <xsl:element name="gentext">
    <xsl:attribute name="type">
      <xsl:value-of select="@kind" />
    </xsl:attribute>
    <xsl:attribute name="data">
      <xsl:value-of select="@data" />
    </xsl:attribute>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- target -->
<xsl:template match="target">
  <xsl:element name="target">
    <xsl:attribute name="id">
      <xsl:value-of select="@name" />
    </xsl:attribute>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- newline -->
<xsl:template match="newline">
  <xsl:element name="linebreak">
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- newcolumn -->
<xsl:template match="newcolumn">
  <xsl:element name="columnbreak">
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- pagebreak -->
<xsl:template match="pagebreak">
  <xsl:element name="pagebreak">
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- indextarget -->
<xsl:template match="indextarget">
  <xsl:element name="indextarget">
    <xsl:copy-of select="@entryLevel1" />
    <xsl:copy-of select="@entryLevel2" />
    <xsl:copy-of select="@entryLevel3" />
    <xsl:copy-of select="@entryLevel4" />
    <xsl:copy-of select="@entryLevel5" />
    <xsl:copy-of select="@entryLevel6" />
    <xsl:copy-of select="@entryLevel7" />
    <xsl:copy-of select="@entryLevel8" />
    <xsl:copy-of select="@entryLevel9" />
    <xsl:if test="@main">
      <xsl:attribute name="entryLevel1"><xsl:value-of select="@main"/></xsl:attribute>
    </xsl:if>
    <xsl:if test="@sub">
      <xsl:attribute name="entryLevel2"><xsl:value-of select="@sub"/></xsl:attribute>
    </xsl:if>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- pageheader -->
<xsl:template match="pageheader">
  <xsl:element name="pageheader">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- pagefooter -->
<xsl:template match="pagefooter">
  <xsl:element name="pagefooter">
    <xsl:call-template name="copy-all-attributes" />
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


<!-- toc -->
<xsl:template match="toc">
  <xsl:element name="toc">
    <xsl:attribute name="data">
      <xsl:text>\o &amp;quot;1-3&amp;quot; \h \z</xsl:text> <!-- we use some hopefully acceptable default value for TOC rendering -->
    </xsl:attribute>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>


</xsl:stylesheet>

