view software/mpdl-services/mpiwg-mpdl-cms/bin/de/mpg/mpiwg/berlin/mpdl/cms/transform/pageTei.xsl @ 23:e845310098ba

diverse Korrekturen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Nov 2012 12:35:19 +0100
parents
children
line wrap: on
line source

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:functx="http://www.functx.com"
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:dcterms="http://purl.org/dc/terms"
  xmlns:math="http://www.w3.org/1998/Math/MathML"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="xsl xlink xs functx saxon dc dcterms math svg xhtml"
  >

<xsl:output method="xhtml" encoding="utf-8"/>

<xsl:param name="echoFiguresDir"></xsl:param>
<xsl:param name="echoPageImgDir"></xsl:param>

<xsl:variable name="dictionaryServiceName" select="'http://mpdl-service.mpiwg-berlin.mpg.de/mpiwg-mpdl-lt-web/lt/GetDictionaryEntries'"/>

<xsl:template match="*:TEI">
  <div>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'TEI'"/></xsl:attribute>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<xsl:template match="*:expan|*:emph|*:q|*:quote|*:reg|*:num">
  <xsl:element name="span">
    <xsl:attribute name="class"><xsl:value-of select="name()"/></xsl:attribute>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

<xsl:template match="*:teiHeader">
  <!-- do nothing -->
</xsl:template>

<xsl:template match="*:text">
  <xsl:variable name="contentStr" select="normalize-space(string(.))"/>
  <xsl:variable name="figures" select=".//*:figure|.//*:handwritten"/>
  <div>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'text'"/></xsl:attribute>
    <xsl:apply-templates/>
    <xsl:if test="$contentStr = '' and empty($figures)">  <!-- test if div only contains empty nodes but no figures -->
      <div>
        <xsl:attribute name="class"><xsl:value-of select="'emptyPage'"/></xsl:attribute>
        <xsl:value-of select="'[Empty page]'"/>
      </div>
    </xsl:if>
  </div>
  <!--   Dictionary                      -->
  <xsl:if test="not(empty(//*:entry))">
    <xsl:for-each select="//*:entry">
      <xsl:sort select="*:form/*:orth"/>
      <xsl:variable name="position" select="position()"/>
      <span class="entry">
        <xsl:apply-templates select="*:form"/>
        <xsl:apply-templates select="*:sense"/>
        <xsl:if test="not(empty(*:figure))">
          <span class="entryDiv">
            <span class="bf"><xsl:value-of select="'Figures: '"/></span>
            <span class="entryDiv">
              <xsl:for-each select="*:figure">
                <xsl:variable name="href" select="*:graphic/@url"/>
                <xsl:variable name="figDesc" select="string(*:figDesc)"/>
                <xsl:if test="$href != ''">
                  <div class="figure" style="margin-left:10px;">
                    <a href="{$href}"><img alt="Figure: {$figDesc}" src="{$href}" width="200" height="200"/></a>
                    <br/>
                    <xsl:value-of select="'[Figure]: '"/><xsl:apply-templates select="*:head"/>
                  </div>
                </xsl:if>
              </xsl:for-each>
            </span>
          </span>
        </xsl:if>
        <xsl:if test="not(empty(*:xr))">
          <span class="entryDiv">
            <span class="bf"><xsl:value-of select="'References: '"/></span>
            <span class="entryDiv">
              <xsl:for-each select="*:xr/*:ref">
                <li><xsl:apply-templates select="."/></li>
              </xsl:for-each>
            </span>
          </span>
        </xsl:if>
      </span>
    </xsl:for-each>  
  </xsl:if>
  <!--   Notes                      -->
  <xsl:variable name="bottomNotes" select="//*:note[contains(@place, 'foot') or empty(string(@place))]"/>
  <xsl:variable name="countBottomNotes" select="count($bottomNotes)"/>
  <xsl:if test="$countBottomNotes > 0">
    <span class="notes">
      <xsl:for-each select="$bottomNotes">
        <xsl:variable name="noteSign"><xsl:value-of select="count(./preceding::*:note) + 1"/></xsl:variable>
        <span>
          <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
          <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
          <span class="noteSign"><xsl:value-of select="$noteSign"/></span>
          <span>
            <xsl:attribute name="class"><xsl:value-of select="'noteBody foot'"/></xsl:attribute>
            <span class="noteSign"><xsl:value-of select="$noteSign"/></span>
            <xsl:apply-templates/>
          </span>
        </span>
      </xsl:for-each>
    </span>
  </xsl:if>
</xsl:template>

<xsl:template match="*:div">
  <xsl:if test="node() or normalize-space()">  <!-- test: contains nodes or is not empty -->
    <div>
      <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
      <xsl:attribute name="class"><xsl:value-of select="'div'"/></xsl:attribute>
      <xsl:apply-templates/>
    </div>
  </xsl:if>
</xsl:template>

<xsl:template match="*:p">
  <div>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'p'"/></xsl:attribute>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<xsl:template match="*:pb">
  <xsl:variable name="number">
    <xsl:choose>
      <xsl:when test="not(empty(@n))"><xsl:value-of select="@n"/></xsl:when>
      <xsl:otherwise><xsl:value-of select="count(./preceding::*:pb) + 1"/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="file">
    <xsl:choose>
      <xsl:when test="not(empty(@facs))"><xsl:value-of select="@facs"/></xsl:when>
      <xsl:otherwise><xsl:value-of select="$number"/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'pb'"/></xsl:attribute>
    <span>
      <xsl:attribute name="class"><xsl:value-of select="'src'"/></xsl:attribute>
      <xsl:attribute name="title"><xsl:value-of select="concat('pageimg/', string($file))"/></xsl:attribute>
      <span>
        <xsl:attribute name="class"><xsl:value-of select="'n'"/></xsl:attribute>
        <xsl:value-of select="$number"/>
      </span>
    </span>
  </span>
</xsl:template>

<xsl:template match="*:head">
  <div>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'head bf'"/></xsl:attribute>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<xsl:template match="*:figure">
  <span class="figure">
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:variable name="url">
      <xsl:choose>
        <xsl:when test="not(empty(@facs))"><xsl:value-of select="string(@facs)"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="string(graphic/@url)"/></xsl:otherwise>
     </xsl:choose>
    </xsl:variable>
    <xsl:variable name="fileName" select="concat($echoFiguresDir, '/', $url)"/>
    <xsl:variable name="digilibUrl">
      <xsl:choose>
        <xsl:when test="starts-with($url, 'http')"><xsl:value-of select="$url"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="concat('http://digilib.mpiwg-berlin.mpg.de/digitallibrary/jquery/digilib.html?fn=', $fileName)"/></xsl:otherwise>
     </xsl:choose>
    </xsl:variable>
    <xsl:variable name="scalerUrl">
      <xsl:choose>
        <xsl:when test="starts-with($url, 'http')"><xsl:value-of select="$url"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="concat('http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=', $fileName, '&amp;dh=200&amp;dw=200')"/></xsl:otherwise>
     </xsl:choose>
    </xsl:variable>
    <a href="{$digilibUrl}">
      <img>
        <xsl:attribute name="src"><xsl:value-of select="$scalerUrl"/></xsl:attribute>
      </img>
    </a>
    <xsl:if test="not(empty(@number))">
      <span>
        <xsl:attribute name="class"><xsl:value-of select="'figureNumber'"/></xsl:attribute>
        <span>
          <xsl:attribute name="class"><xsl:value-of select="'figureNum'"/></xsl:attribute>
          <xsl:value-of select="string(@number)"/>
        </span>
        <span>
          <xsl:attribute name="class"><xsl:value-of select="'figureNumText'"/></xsl:attribute>
          <xsl:value-of select="concat('[', 'Figure', ' ', string(@number), ']')"/>
        </span>
      </span>
    </xsl:if>
    <xsl:if test="not(empty(*:head))">
      <span class="caption">
        <xsl:for-each select="*:head">
          <xsl:apply-templates/>
        </xsl:for-each>
      </span>
    </xsl:if>
  </span>
</xsl:template>

<!-- segmentation   -->
<xsl:template match="*:seg">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:choose>
      <xsl:when test="@rend = 'highlight'">
        <xsl:attribute name="class"><xsl:value-of select="'seg highlight'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="@rend = 'highlightPoint'">
        <xsl:attribute name="class"><xsl:value-of select="'seg highlightPoint'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="class"><xsl:value-of select="'seg'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </span>
</xsl:template>

<!-- choice   -->
<xsl:template match="*:choice">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'choice'"/></xsl:attribute>
    <xsl:if test="not(empty(*:orig))">
      <xsl:apply-templates select="*:orig"/>
    </xsl:if>
    <xsl:if test="not(empty(*:abbr))">
      <xsl:apply-templates select="*:abbr"/>
    </xsl:if>
    <xsl:if test="not(empty(*:am))">
      <xsl:apply-templates select="*:am"/>
    </xsl:if>
    <xsl:if test="not(empty(*:sic))">
      <xsl:apply-templates select="*:sic"/>
    </xsl:if>
  </span>
</xsl:template>

<!-- hi (highlighted)  -->
<xsl:template match="*:hi">
  <xsl:choose>
    <xsl:when test="not(empty(@type)) and @type = 'elem'">
      <div>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:attribute name="class"><xsl:value-of select="concat('highlight ', @type)"/></xsl:attribute>
        <xsl:apply-templates/>
      </div>
    </xsl:when>
    <xsl:when test="not(empty(@type)) and @type != 'elem'">
      <span>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:attribute name="class"><xsl:value-of select="concat('highlight ', @type)"/></xsl:attribute>
        <xsl:apply-templates/>
      </span>
    </xsl:when>
    <xsl:when test="@rend = 'initial'">
      <span>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:attribute name="class"><xsl:value-of select="'initial'"/></xsl:attribute>
        <xsl:apply-templates/>
      </span>
    </xsl:when>
    <xsl:when test="@rend = 'bold'">
      <span>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:attribute name="class"><xsl:value-of select="'bf'"/></xsl:attribute>
        <xsl:apply-templates/>
      </span>
    </xsl:when>
    <xsl:otherwise>
      <span>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:attribute name="class"><xsl:value-of select="@rend"/></xsl:attribute>
        <xsl:apply-templates/>
      </span>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- name (of type: place, person, ...)   -->
<xsl:template match="*:name">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:choose>
      <xsl:when test="@type = 'place'">
        <xsl:attribute name="class"><xsl:value-of select="'place'"/></xsl:attribute>
        <xsl:attribute name="title"><xsl:value-of select="'Place'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="@type = 'person'">
        <xsl:attribute name="class"><xsl:value-of select="'person'"/></xsl:attribute>
        <xsl:attribute name="title"><xsl:value-of select="'Person'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="@type = 'org'">
        <xsl:attribute name="class"><xsl:value-of select="'organization'"/></xsl:attribute>
        <xsl:attribute name="title"><xsl:value-of select="'Organization'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:attribute name="class"><xsl:value-of select="@type"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </span>
</xsl:template>

<!-- place, person, ...)   -->
<xsl:template match="*:placeName">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'place'"/></xsl:attribute>
    <xsl:attribute name="title"><xsl:value-of select="concat('Place: ', @type)"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>
<xsl:template match="*:persName">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'person'"/></xsl:attribute>
    <xsl:attribute name="title"><xsl:value-of select="'Person'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<!-- term    -->
<xsl:template match="*:term">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'term'"/></xsl:attribute>
    <xsl:attribute name="title"><xsl:value-of select="'Terminology entry'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<!-- line    -->
<xsl:template match="*:lg">
  <div>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'lg'"/></xsl:attribute>
    <xsl:apply-templates/>
  </div>
</xsl:template>

<xsl:template match="*:l">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'l'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
  <br/>
</xsl:template>

<!-- reference    -->
<xsl:template match="*:ref">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'ref'"/></xsl:attribute>
    <xsl:if test="not(empty(@target))">
      <a class="ref">
        <xsl:attribute name="href"><xsl:value-of select="@target"/></xsl:attribute>
        <xsl:apply-templates/>
      </a>
    </xsl:if>
    <xsl:if test="empty(@target)">
      <xsl:apply-templates/>
    </xsl:if>
  </span>
</xsl:template>

<!-- table    -->
<xsl:template match="*:table">
  <table>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:if test="not(empty(head))">
      <caption align="top"><xsl:apply-templates select="*:head"/></caption>
    </xsl:if>
    <xsl:apply-templates select="*:row"/>
  </table>
</xsl:template>

<xsl:template match="*:row">
  <tr>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:choose>
      <xsl:when test="@role = 'label'">
        <xsl:attribute name="style"><xsl:value-of select="'font-weight:bold;'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="@role = 'data' or empty(@role)">
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </tr>
</xsl:template>

<xsl:template match="*:cell">
  <td>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:choose>
      <xsl:when test="@role = 'label' and empty(@cols)">
        <xsl:attribute name="style"><xsl:value-of select="'font-weight:bold;'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="@role = 'label' and not(empty(@cols))">
        <xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
        <xsl:attribute name="style"><xsl:value-of select="'font-weight:bold;'"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="(@role = 'data' or empty(@role)) and empty(@cols)">
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:when test="(@role = 'data' or empty(@role)) and not(empty(@cols))">
        <xsl:attribute name="colspan"><xsl:value-of select="@cols"/></xsl:attribute>
        <xsl:apply-templates/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </td>
</xsl:template>

<!-- dictionary    -->
<xsl:template match="*:entry">
  <!-- empty: handled in text tag    -->
</xsl:template>

<xsl:template match="*:form">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'form'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<xsl:template match="*:orth">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'orth'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<xsl:template match="*:sense">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'sense'"/></xsl:attribute>
    <span class="entryDiv"><xsl:apply-templates select="*:def"/></span>
    <span class="entryDiv"><xsl:apply-templates select="*:etym"/></span>
  </span>
</xsl:template>

<xsl:template match="*:def">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'def'"/></xsl:attribute>
    <span class="bf"><xsl:value-of select="'Definition: '"/></span>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<xsl:template match="*:mentioned">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'mentioned'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<xsl:template match="*:etym">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'etym'"/></xsl:attribute>
    <span class="bf"><xsl:value-of select="'Etymology: '"/></span>
    <span class="entryDiv">
      <xsl:for-each select="*:cit">
        <li><xsl:apply-templates select="*:quote"/><xsl:value-of select="' ('"/><xsl:apply-templates select="*:def"/><xsl:value-of select="')'"/></li>
      </xsl:for-each>
    </span>
  </span>
</xsl:template>

<xsl:template match="*:cit">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'cit'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<!-- MathML    -->
<xsl:template match="math:*">
  <xsl:element name="{name()}" namespace="">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

<!-- SVG    -->
<xsl:template match="svg:*">
  <xsl:element name="{name()}" namespace="">
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

<xsl:template match="*:lb">
  <br>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'lb'"/></xsl:attribute>
  </br>
</xsl:template>

<xsl:template match="*:cb">
  <br>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'cb'"/></xsl:attribute>
  </br>
</xsl:template>

<xsl:template match="*:note">
  <xsl:variable name="place"><xsl:value-of select="string(@place)"/></xsl:variable>
  <xsl:variable name="noteSign"><xsl:value-of select="count(./preceding::*:note) + 1"/></xsl:variable>
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
    <span class="noteSign"><xsl:value-of select="$noteSign"/></span>
    <xsl:if test="$place != '' and $place != 'foot'">
      <span>
        <xsl:attribute name="class"><xsl:value-of select="concat('noteBody ', $place)"/></xsl:attribute>
        <span class="noteSign"><xsl:value-of select="$noteSign"/></span>
        <xsl:apply-templates/>
      </span>
    </xsl:if>
  </span>
</xsl:template>

<xsl:template match="*:foreign">
  <xsl:variable name="xmllang" select="@xml:lang"/>
  <xsl:variable name="language">
    <xsl:choose>
      <xsl:when test="not(empty($xmllang))"><xsl:value-of select="$xmllang"/></xsl:when>
      <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>  
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="concat('foreign ', $language)"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<xsl:template match="*:gap">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'gap'"/></xsl:attribute>
    <xsl:if test="not(empty(@extent))"><span class="extent"><xsl:value-of select="string(@extent)"/></span></xsl:if>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<xsl:template match="*:s">
  <span>
    <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
    <xsl:attribute name="class"><xsl:value-of select="'s'"/></xsl:attribute>
    <xsl:apply-templates/>
  </span>
</xsl:template>

<!-- words                            -->
<xsl:template match="*:w">
  <xsl:variable name="wordLanguage" select="@lang"/>
  <xsl:variable name="form" select="encode-for-uri(string(@form))"/>
  <xsl:variable name="dictionary" select="string(@dictionary)"/>
  <xsl:variable name="displayWordOrig">
    <xsl:choose>
      <xsl:when test="not(empty(*:orig))"><xsl:apply-templates select="*:orig/node()"/></xsl:when>
      <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="displayWordReg">
    <xsl:choose>
      <xsl:when test="not(empty(*:reg))"><xsl:apply-templates select="*:reg/node()"/></xsl:when>
      <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="displayWordNorm">
    <xsl:choose>
      <xsl:when test="not(empty(*:norm))"><xsl:apply-templates select="*:norm/node()"/></xsl:when>
      <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="displayWordUrlEncoded" select="encode-for-uri($displayWordOrig)"/>
  <xsl:variable name="dictionaryPart">
    <xsl:choose>
      <xsl:when test="$dictionary = 'true'">
        <a class="dictionary">
          <xsl:attribute name="href"><xsl:value-of select="concat($dictionaryServiceName, '?query=', $form, '&amp;queryDisplay=', $displayWordUrlEncoded, '&amp;language=', $wordLanguage, '&amp;outputFormat=html', '&amp;outputType=morphCompact&amp;outputType=dictFull')"/></xsl:attribute>
          <span class="orig"><xsl:sequence select="$displayWordOrig"/></span>
          <span class="reg"><xsl:sequence select="$displayWordReg"/></span>
          <span class="norm"><xsl:sequence select="$displayWordNorm"/></span>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <span class="dictionary">
          <span class="orig"><xsl:sequence select="$displayWordOrig"/></span>
          <span class="reg"><xsl:sequence select="$displayWordReg"/></span>
          <span class="norm"><xsl:sequence select="$displayWordNorm"/></span>
        </span>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <span class="w">
    <xsl:sequence select="$dictionaryPart"/>
    <span class="nodictionary orig"><xsl:sequence select="$displayWordOrig"/></span>
    <span class="nodictionary reg"><xsl:sequence select="$displayWordReg"/></span>
    <span class="nodictionary norm"><xsl:sequence select="$displayWordNorm"/></span>
  </span>
</xsl:template>

</xsl:stylesheet>