Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
EOASkripts/src/stylesheets/tei2html/utils/numbering.xsl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
315 lines (278 sloc)
11.3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<xsl:stylesheet | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:tei="http://www.tei-c.org/ns/1.0" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xmlns:eoa="http://www.edition-open-access.de/ns" | |
exclude-result-prefixes="xs tei eoa" | |
version="2.0" | |
> | |
<xsl:output | |
method="html" | |
encoding="UTF-8" | |
indent="yes" | |
/> | |
<xsl:variable name="series" select="lower-case(/tei:TEI/tei:teiHeader/tei:fileDesc/tei:seriesStmt/tei:title)"/> | |
<xsl:variable name="publication_number" select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:seriesStmt/tei:idno[@type = 'number']"/> | |
<!-- equations: --> | |
<xsl:template mode="equation_nr_str" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('equation_nr_str called from ', $elem, ' but it is not a equation element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="equation_nr_str" as="xs:string" match="tei:ab[@type = ('equation', 'subequations', 'equationarray')]/tei:formula"> | |
<xsl:variable name="nr"><xsl:apply-templates mode="equation_nr" select="."/></xsl:variable> | |
<xsl:value-of select="if ($nr != '') then concat('(', $nr, ')') else ''"/> | |
</xsl:template> | |
<xsl:template mode="equation_nr" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('equation_nr called from ', $elem, ' but it is not a equation element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="equation_nr" as="xs:string" match="tei:ab[not(@n = 'nonumber')][@type = 'equation']/tei:formula"> | |
<xsl:call-template name="equation_nr_helper"/> | |
</xsl:template> | |
<xsl:template mode="equation_nr" as="xs:string" match="tei:ab[not(@n = 'nonumber')][@type = 'equationarray']/tei:formula"> | |
<xsl:call-template name="equation_nr_helper"/> | |
</xsl:template> | |
<xsl:template mode="equation_nr" as="xs:string" match="tei:ab[not(@n = 'nonumber')][@type = 'subequations']/tei:formula"> | |
<xsl:value-of> | |
<xsl:call-template name="equation_nr_helper"/> | |
<xsl:number | |
count="tei:formula" | |
from = "tei:ab[@type = 'subequations'][not(@n = 'nonumber')]" | |
format="a" | |
level="single" | |
/> | |
</xsl:value-of> | |
</xsl:template> | |
<xsl:template mode="equation_nr" as="xs:string" match="tei:ab[@n = 'nonumber'][@type = ('equation', 'subequations', 'equationarray')]/tei:formula"> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template name="equation_nr_helper" as="xs:string"> | |
<xsl:value-of> | |
<xsl:number | |
count="tei:div[@type = 'chapter'][not(@n = 'nonumber')]" | |
format="1" | |
level="any" | |
/> | |
<xsl:text>.</xsl:text> | |
<xsl:number | |
count = " | |
tei:ab[not(@n = 'nonumber')][@type = 'equation']/tei:formula | |
| tei:ab[not(@n = 'nonumber')][@type = 'subequations'] | |
| tei:ab[not(@n = 'nonumber')][@type = 'equationarray']/tei:formula | |
" | |
from = "tei:div[@type = 'chapter']" | |
format="1" | |
level="any" | |
/> | |
</xsl:value-of> | |
</xsl:template> | |
<!-- table: --> | |
<xsl:template mode="table_nr_prefix" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('table_nr_prefix called from ', $elem, ' but it is not a table element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="table_nr_prefix" as="xs:string" match="tei:table"> | |
<xsl:variable name="nr"><xsl:apply-templates mode="table_nr" select="."/></xsl:variable> | |
<xsl:value-of select="if ($nr != '') then concat($nr, ' ') else ''"/> | |
</xsl:template> | |
<xsl:template mode="table_nr" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('table_nr called from ', $elem, ' but it is not a table element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="table_nr" as="xs:string" match="tei:table[tei:head]"> | |
<xsl:number | |
count="tei:table[tei:head] | tei:div[@type = 'chapter'][not(@n = 'nonumber')]" | |
format="1.1" | |
level="multiple" | |
/> | |
</xsl:template> | |
<xsl:template mode="table_nr" as="xs:string" match="tei:table[not(tei:head)]"> | |
<xsl:text/> | |
</xsl:template> | |
<!-- figure: --> | |
<xsl:template mode="figure_nr_prefix" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('figure_nr_prefix called from ', $elem, ' but it is not a figure element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="figure_nr_prefix" as="xs:string" match="tei:figure"> | |
<xsl:variable name="nr"><xsl:apply-templates mode="figure_nr" select="."/></xsl:variable> | |
<xsl:value-of select="if ($nr != '') then concat($nr, ' ') else ''"/> | |
</xsl:template> | |
<xsl:template mode="figure_nr" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('figure_nr called from ', $elem, ' but it is not a figure element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="figure_nr" as="xs:string" match="tei:figure[tei:head]"> | |
<xsl:number | |
count="tei:figure[tei:head] | tei:div[@type = 'chapter'][not(@n = 'nonumber')]" | |
format="1.1" | |
level="multiple" | |
/> | |
</xsl:template> | |
<xsl:template mode="figure_nr" as="xs:string" match="tei:figure[not(tei:head)]"> | |
<xsl:text/> | |
</xsl:template> | |
<!-- chapter and sections --> | |
<xsl:template name="chapter_id" as="xs:int"> | |
<xsl:number | |
count="tei:div[@type = 'chapter']" | |
from="tei:div[@type = 'part']" | |
level="any" | |
/> | |
</xsl:template> | |
<xsl:template mode="section_nr_prefix" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('section_nr_prefix called from ', $elem, ' but it is not a section element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="section_nr_prefix" as="xs:string" match="tei:div[@type = ('chapter', 'section', 'subsection')]"> | |
<xsl:variable name="section_nr"><xsl:apply-templates mode="section_nr" select="."/></xsl:variable> | |
<xsl:value-of select="if ($section_nr != '') then concat($section_nr, ' ') else ''"/> | |
</xsl:template> | |
<xsl:template mode="section_nr" as="xs:string" match="*" priority="-100"> | |
<xsl:variable name="elem"><xsl:call-template name="eoa:print_elem"/></xsl:variable> | |
<xsl:sequence select="eoa:warning(concat('section_nr called from ', $elem, ' but it is not a section element.'))"/> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="section_nr" as="xs:string" match="tei:div[@n = 'nonumber']" priority="-50"> | |
<xsl:text/> | |
</xsl:template> | |
<xsl:template mode="section_nr" as="xs:string" match="tei:div[@type = 'chapter']"> | |
<xsl:number | |
count="tei:div[not(@n = 'nonumber')][@type = ('chapter')]" | |
format="1" | |
level="multiple" | |
/> | |
</xsl:template> | |
<xsl:template mode="section_nr" as="xs:string" match="tei:div[@type = 'section']"> | |
<xsl:number | |
count="tei:div[not(@n = 'nonumber')][@type = ('chapter', 'section')]" | |
format="1" | |
level="multiple" | |
/> | |
</xsl:template> | |
<xsl:template mode="section_nr" as="xs:string" match="tei:div[@type = 'subsection']"> | |
<xsl:number | |
count="tei:div[not(@n = 'nonumber')][@type = ('chapter', 'section', 'subsection')]" | |
format="1" | |
level="multiple" | |
/> | |
</xsl:template> | |
<!-- if the current element is a "paragraph level element", return its id in the document. Otherwise return the empty sequence --> | |
<xsl:template name="container_id" as="xs:string?"> | |
<xsl:choose> | |
<xsl:when test=" | |
( | |
self::tei:div[@type = ('section', 'subsection', 'subsubsection', 'sidebyside', 'bilingual')] | |
| self::tei:p | |
| self::tei:milestone[@type='divider'] | |
| self::tei:epigraph | |
| self::tei:ab | |
| self::tei:lg | |
| self::tei:quote | |
| self::tei:list | |
| self::tei:table | |
| self::tei:figure | |
| self::tei:div[@type = 'letter'] | |
)[ | |
parent::tei:div[@type = ('chapter', 'section', 'subsection', 'subsubsection')] | |
]" | |
> | |
<xsl:number | |
count=" | |
( | |
tei:div[@type = ('section', 'subsection', 'subsubsection', 'sidebyside', 'bilingual')] | |
| tei:p | |
| tei:milestone[@type='divider'] | |
| tei:epigraph | |
| tei:ab | |
| tei:lg | |
| tei:quote | |
| tei:list | |
| tei:table | |
| tei:figure | |
| tei:div[@type = 'letter'] | |
)[ | |
parent::tei:div[@type = ('chapter', 'section', 'subsection', 'subsubsection')] | |
]" | |
from="tei:div[@type = 'chapter']" | |
level="any" | |
/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="()"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="uri_from_frontpage" as="xs:string"> | |
<xsl:variable name="chapter" select="ancestor-or-self::tei:div[@type = 'chapter']"/> | |
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*) + 1"/> | |
<xsl:choose> | |
<xsl:when test="self::tei:div[@type ='chapter']"> | |
<xsl:value-of select="concat('./', $chapter_nr , '/index.html')"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable> | |
<xsl:value-of select="concat('./', $chapter_nr , '/index.html#', $container_id)"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="uri_from_chapter" as="xs:string"> | |
<xsl:variable name="chapter" select="ancestor-or-self::tei:div[@type = 'chapter']"/> | |
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/> | |
<xsl:choose> | |
<xsl:when test="self::tei:div[@type ='chapter']"> | |
<xsl:value-of select="concat('../', $chapter_nr , '/index.html')"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable> | |
<xsl:value-of select="concat('../', $chapter_nr , '/index.html#', $container_id)"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="full_uri_from_chapter" as="xs:string"> | |
<xsl:choose> | |
<xsl:when test="$platform_uri != ''"> | |
<xsl:variable name="chapter" select="ancestor-or-self::tei:div[@type = 'chapter']"/> | |
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/> | |
<xsl:variable name="uri" select="concat($platform_uri, '/', $series, '/', $publication_number, '/', $chapter_nr , '/index.html')"/> | |
<xsl:choose> | |
<xsl:when test="self::tei:div[@type ='chapter']"> | |
<xsl:value-of select="$uri"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable> | |
<xsl:value-of select="concat($uri, '#', $container_id)"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:call-template name="uri_from_chapter"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="footnote_id" as="xs:string?"> | |
<xsl:choose> | |
<xsl:when test="self::tei:note"> | |
<value-of> | |
<xsl:text>fn</xsl:text> | |
<xsl:number | |
count="tei:note" | |
from="tei:div[@type = 'chapter']" | |
level="any" | |
/> | |
</value-of> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="()"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |