Mode:

Compact lists

Showing:

Documentation
Used by
References
Overriding
Included from
Source
Stylesheet figures.xsl
Documentation

Description

TEI stylesheet dealing with elements from the figures module, making HTML output.

This software is dual-licensed: 1. Distributed under a Creative Commons Attribution-ShareAlike 3.0 Unported License http://creativecommons.org/licenses/by-sa/3.0/ 2. http://www.opensource.org/licenses/BSD-2-Clause All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright holder or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.

Author: See AUTHORS

Id: $Id: figures.xsl 12078 2013-05-05 12:51:58Z rahtz $

Copyright: 2013, TEI Consortium

Included from
Stylesheet version 2.0
Template m:*math
Documentation

Description

Processing MathML to avoid prefixes (upsets browsers)
Namespace No namespace
Match m:*
Mode math
Import precedence 13
Source
<xsl:template match="m:*" mode="math">
  <xsl:element name="{local-name()}" namespace="http://www.w3.org/1998/Math/MathML">
    <xsl:apply-templates select="node() | @*" mode="math"/>
  </xsl:element>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template @*|comment()|processing-instruction()|text()math
Namespace No namespace
Match @*|comment()|processing-instruction()|text()
Mode math
Import precedence 13
Source
<xsl:template match="@*|comment()|processing-instruction()|text()" mode="math">
  <xsl:copy>
    <xsl:apply-templates mode="math" select="*|@*|processing-instruction()|text()"/>
  </xsl:copy>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template m:math
Documentation

Description

Process elements m:math
Namespace No namespace
Match m:math
Mode #default
Import precedence 13
Source
<xsl:template match="m:math">
  <xsl:apply-templates mode="math" select="."/>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:cell
Documentation

Description

Process element cell
Namespace No namespace
Match tei:cell
Mode #default
References
Parameter
Template
Import precedence 13
Source
<xsl:template match="tei:cell">
  <xsl:variable name="cellname">
    <xsl:choose>
      <xsl:when test="parent::tei:row[@rend='thead']">th</xsl:when>
      <xsl:otherwise>td</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:element name="{$cellname}">
    <xsl:for-each select="@*">
      <xsl:choose>
        <xsl:when test="name(.) = 'width' or name(.) =      'border' or name(.) = 'cellspacing'      or name(.) = 'cellpadding'">
          <xsl:copy-of select="."/>
        </xsl:when>
        <xsl:when test="name(.)='rend' and starts-with(.,'width:')">
          <xsl:attribute name="width">
            <xsl:value-of select="substring-after(.,'width:')"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="name(.)='rend' and starts-with(.,'class:')">
          <xsl:attribute name="class">
            <xsl:value-of select="substring-after(.,'class:')"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="name(.)='rend' and starts-with(.,'style=')">
          <xsl:attribute name="style">
            <xsl:value-of select="substring-after(.,'style=')"/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="name(.)='rend'">
          <xsl:attribute name="class">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="name(.)='cols'">
          <xsl:attribute name="colspan">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="name(.)='rows'">
          <xsl:attribute name="rowspan">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:when>
        <xsl:when test="name(.)='align'">
          <xsl:attribute name="align">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
    <xsl:choose>
      <xsl:when test="@teidocx:align">
        <xsl:attribute name="align">
          <xsl:value-of select="@teidocx:align"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:when test="@align"/>
      <xsl:when test="not($cellAlign='left')">
        <xsl:attribute name="align">
          <xsl:value-of select="$cellAlign"/>
        </xsl:attribute>
      </xsl:when>
    </xsl:choose>
    <xsl:if test="@role and not (@rend)">
      <xsl:attribute name="class">
        <xsl:value-of select="@role"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test="@xml:id">
      <xsl:call-template name="makeAnchor"/>
    </xsl:if>
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:figDesc
Documentation

Description

Process element figDesc
Namespace No namespace
Match tei:figDesc
Mode #default
Import precedence 13
Source
<xsl:template match="tei:figDesc">
  <xsl:if test="count(parent::tei:figure/*)=1">
    <i>
      <xsl:text>[</xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>]</xsl:text>
    </i>
  </xsl:if>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:figure
Documentation

Description

Process element figure
Namespace No namespace
Match tei:figure
Mode #default
References
Import precedence 13
Source
<xsl:template match="tei:figure">
  <xsl:choose>
    <xsl:when test="@rend='inline' or @place='inline'">
      <xsl:apply-templates/>
    </xsl:when>
    <xsl:when test="parent::tei:hi/parent::tei:date or parent::tei:ref or parent::tei:label">
      <xsl:apply-templates/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:element name="{if ($outputTarget='html5') then 'figure'       else if (tei:is-inline(.)) then 'span'       else 'div'}">
        <xsl:call-template name="makeRendition">
          <xsl:with-param name="auto">figure</xsl:with-param>
        </xsl:call-template>
        <xsl:if test="@xml:id">
          <xsl:attribute name="id">
            <xsl:value-of select="@xml:id"/>
          </xsl:attribute>
        </xsl:if>
        <xsl:call-template name="figureHook"/>
        <xsl:choose>
          <xsl:when test="not(*)">
            <i>
              <xsl:text>[figure]</xsl:text>
            </i>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:element>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:figure/tei:head
Documentation

Description

Process element figure/tei:head
Namespace No namespace
Match tei:figure/tei:head
Mode #default
References
Import precedence 13
Source
<xsl:template match="tei:figure/tei:head">
  <xsl:variable name="captionlabel">
    <xsl:for-each select="..">
      <xsl:call-template name="calculateFigureNumber"/>
    </xsl:for-each>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$outputTarget='html5'">
      <figcaption>
        <xsl:call-template name="makeRendition">
          <xsl:with-param name="default">caption</xsl:with-param>
        </xsl:call-template>
        <xsl:copy-of select="$captionlabel"/>
        <xsl:if test="not($captionlabel='')">
          <xsl:text>. </xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
      </figcaption>
    </xsl:when>
    <xsl:otherwise>
      <xsl:element name="{if (ancestor::tei:q) then 'span' else 'div'}">
        <xsl:call-template name="makeRendition">
          <xsl:with-param name="default">caption</xsl:with-param>
        </xsl:call-template>
        <xsl:copy-of select="$captionlabel"/>
        <xsl:if test="not($captionlabel='')">
          <xsl:text>. </xsl:text>
        </xsl:if>
        <xsl:apply-templates/>
      </xsl:element>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:formulaxref
Documentation

Description

Process element formula
Namespace No namespace
Match tei:formula
Mode xref
Import precedence 13
Source
<xsl:template match="tei:formula" mode="xref">
  <xsl:number/>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:graphic|tei:binaryObject
Documentation

Description

Process element graphic
Namespace No namespace
Match tei:graphic|tei:binaryObject
Mode #default
References
Template
Import precedence 13
Source
<xsl:template match="tei:graphic|tei:binaryObject">
  <xsl:call-template name="showGraphic"/>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:row
Documentation

Description

Process element row
Namespace No namespace
Match tei:row
Mode #default
References
Template
Overriding
Template
Import precedence 13
Source
<xsl:template match="tei:row">
  <tr>
    <xsl:call-template name="makeRendition">
      <xsl:with-param name="default">false</xsl:with-param>
    </xsl:call-template>
    <xsl:if test="@role">
      <xsl:attribute name="class">
        <xsl:value-of select="@role"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
  </tr>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:table
Documentation

Description

Process element table
Namespace No namespace
Match tei:table
Mode #default
References
Import precedence 13
Source
<xsl:template match="tei:table">
  <div>
    <xsl:attribute name="class">
      <xsl:text>table</xsl:text>
      <xsl:if test="@align">
        <xsl:text> </xsl:text>
        <xsl:value-of select="@align"/>
      </xsl:if>
    </xsl:attribute>
    <xsl:if test="@xml:id">
      <xsl:call-template name="makeAnchor"/>
    </xsl:if>
    <table>
      <xsl:call-template name="makeRendition">
        <xsl:with-param name="default">false</xsl:with-param>
      </xsl:call-template>
      <xsl:if test="@rend='frame' or @rend='rules'">
        <xsl:attribute name="rules">all</xsl:attribute>
        <xsl:attribute name="border">1</xsl:attribute>
      </xsl:if>
      <xsl:for-each select="@*">
        <xsl:if test="name(.)='summary' or name(.) = 'width' or name(.) = 'border' or name(.) = 'frame' or name(.) = 'rules' or name(.) = 'cellspacing' or name(.) = 'cellpadding'">
          <xsl:copy-of select="."/>
        </xsl:if>
      </xsl:for-each>
      <xsl:if test="tei:head">
        <caption>
          <xsl:apply-templates select="tei:head"/>
        </caption>
      </xsl:if>
      <xsl:choose>
        <xsl:when test="tei:row[@rend='thead']">
          <thead>
            <xsl:apply-templates select="tei:row[@rend='thead']"/>
          </thead>
          <tbody>
            <xsl:apply-templates select="tei:row[not(@rend='thead')]"/>
          </tbody>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="tei:row"/>
        </xsl:otherwise>
      </xsl:choose>
    </table>
    <xsl:apply-templates select="tei:note"/>
  </div>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:table[@rend='simple']
Documentation

Description

Process element table[@rend='simple']
Namespace No namespace
Match tei:table[@rend='simple']
Mode #default
References
Import precedence 13
Source
<xsl:template match="tei:table[@rend='simple']">
  <table>
    <xsl:call-template name="makeRendition">
      <xsl:with-param name="default">false</xsl:with-param>
    </xsl:call-template>
    <xsl:for-each select="@*">
      <xsl:if test="name(.)='summary'    or name(.) = 'width'    or name(.) = 'border'    or name(.) = 'frame'    or name(.) = 'rules'    or name(.) = 'cellspacing'    or name(.) = 'cellpadding'">
        <xsl:copy-of select="."/>
      </xsl:if>
    </xsl:for-each>
    <xsl:if test="@xml:id">
      <xsl:call-template name="makeAnchor"/>
    </xsl:if>
    <xsl:apply-templates/>
  </table>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template showGraphic
Documentation

Description

[html] display graphic file
Namespace No namespace
Used by
References
Import precedence 13
Source
<xsl:template name="showGraphic">
  <xsl:variable name="File">
    <xsl:choose>
      <xsl:when test="self::tei:binaryObject"/>
      <xsl:when test="@url">
        <xsl:sequence select="tei:resolveURI(.,@url)"/>
        <xsl:if test="not(contains(@url,'.'))">
          <xsl:value-of select="$graphicsSuffix"/>
        </xsl:if>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">Cannot work out how to do a graphic, needs a URL</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="Alt">
    <xsl:choose>
      <xsl:when test="tei:desc">
        <xsl:for-each select="tei:desc">
          <xsl:apply-templates mode="plain"/>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="tei:figDesc">
        <xsl:for-each select="tei:figDesc">
          <xsl:apply-templates mode="plain"/>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="tei:head">
        <xsl:value-of select="tei:head/text()"/>
      </xsl:when>
      <xsl:when test="parent::tei:figure/tei:figDesc">
        <xsl:for-each select="parent::tei:figure/tei:figDesc">
          <xsl:apply-templates mode="plain"/>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="parent::tei:figure/tei:head">
        <xsl:value-of select="parent::tei:figure/tei:head/text()"/>
      </xsl:when>
    </xsl:choose>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="$showFigures='true'">
      <xsl:choose>
        <xsl:when test="@type='thumbnail'"/>
        <xsl:when test="starts-with(@mimeType, 'video')">
          <video src="{$graphicsPrefix}{$File}" controls="controls">
            <xsl:if test="../tei:graphic[@type='thumbnail']">
              <xsl:attribute name="poster">
                <xsl:value-of select="../tei:graphic[@type='thumbnail']/@url"/>
              </xsl:attribute>
            </xsl:if>
          </video>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="sizes">
            <xsl:if test="@width">
              <xsl:text> width:</xsl:text>
              <xsl:value-of select="@width"/>
              <xsl:text>;</xsl:text>
            </xsl:if>
            <xsl:if test="@height">
              <xsl:text> height:</xsl:text>
              <xsl:value-of select="@height"/>
              <xsl:text>;</xsl:text>
            </xsl:if>
          </xsl:variable>
          <xsl:variable name="i">
            <img>
              <xsl:attribute name="src">
                <xsl:choose>
                  <xsl:when test="self::tei:binaryObject">
                    <xsl:text>data:</xsl:text>
                    <xsl:value-of select="@mimetype"/>
                    <xsl:variable name="enc" select="if (@encoding) then @encoding else 'base64'"/>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="$enc"/>
                    <xsl:text>,</xsl:text>
                    <xsl:copy-of select="text()"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="concat($graphicsPrefix,$File)"/>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              <xsl:attribute name="alt">
                <xsl:value-of select="$Alt"/>
              </xsl:attribute>
              <xsl:call-template name="imgHook"/>
              <xsl:if test="@xml:id">
                <xsl:attribute name="id">
                  <xsl:value-of select="@xml:id"/>
                </xsl:attribute>
              </xsl:if>
              <xsl:call-template name="makeRendition"/>
            </img>
          </xsl:variable>
          <xsl:for-each select="$i/*">
            <xsl:copy>
              <xsl:copy-of select="@*[not(name()='style')]"/>
              <xsl:choose>
                <xsl:when test="$sizes=''">
                  <xsl:copy-of select="@style"/>
                </xsl:when>
                <xsl:when test="not(@style)">
                  <xsl:attribute name="style" select="$sizes"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:attribute name="style" select="concat(@style,';' ,$sizes)"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:copy>
          </xsl:for-each>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <div class="altfigure">
        <xsl:sequence select="tei:i18n('figureWord')"/>
        <xsl:text> </xsl:text>
        <xsl:for-each select="self::tei:figure|parent::tei:figure">
          <xsl:number count="tei:figure[tei:head]" level="any"/>
        </xsl:for-each>
        <xsl:text> </xsl:text>
        <xsl:value-of select="$File"/>
        <xsl:text> [</xsl:text>
        <xsl:value-of select="$Alt"/>
        <xsl:text>] </xsl:text>
      </div>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template svg:*
Namespace No namespace
Match svg:*
Mode #default
Import precedence 13
Source
<xsl:template match="svg:*">
  <xsl:copy-of select="."/>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:figure[svg:svg]
Documentation

Description

[html] figures containing SVG markup
Namespace No namespace
Match tei:figure[svg:svg]
Mode #default
Import precedence 13
Source
<xsl:template match="tei:figure[svg:svg]">
  <xsl:copy-of select="svg:svg"/>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl
Template tei:formula[m:math]
Documentation

Description

[html] figures containing MathML Markup
Namespace No namespace
Match tei:formula[m:math]
Mode #default
Import precedence 13
Source
<xsl:template match="tei:formula[m:math]">
  <xsl:choose>
    <xsl:when test="@xml:id and (@rend='display' or    @rend='equation' or @rend='subeqn')">
      <div id="{@xml:id}">
        <xsl:apply-templates select="m:math" mode="math"/>
      </div>
    </xsl:when>
    <xsl:when test="@xml:id">
      <span id="{@xml:id}">
        <xsl:apply-templates select="m:math" mode="math"/>
      </span>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="m:math" mode="math"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Stylesheet location ../xhtml2/figures.xsl