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/index.xsl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
124 lines (117 sloc)
4.32 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:variable name="index_types" as="xs:string*" select="('keyword', 'location', 'person')"/> | |
<!-- | |
collect all tei:index elements and group them | |
into a intermediate xml tree for further processing/rendering | |
--> | |
<xsl:template name="create_index" as="element(eoa:index)"> | |
<xsl:param name="indextype"/> | |
<xsl:sequence select="eoa:info(concat('creating index ', $indextype))"/> | |
<!-- all index elements starting with the same letter: --> | |
<eoa:index type="{$indextype}"> | |
<xsl:for-each-group | |
select="//tei:body//tei:index[lower-case(@indexName) = $indextype][not(ancestor::tei:index)]" | |
group-by="if (exists(tei:term/@sortKey)) then tei:term/@sortKey else tei:term/text()" | |
> | |
<xsl:sort select="current-grouping-key()"/> | |
<xsl:call-template name="calc_index_term"> | |
<xsl:with-param name="term" select="current-grouping-key()"/> | |
<xsl:with-param name="elements" select="current-group()"/> | |
</xsl:call-template> | |
</xsl:for-each-group> | |
</eoa:index> | |
<xsl:sequence select="eoa:info('finished creating index')"/> | |
</xsl:template> | |
<!-- utilities: --> | |
<xsl:template name="calc_index_term"> | |
<xsl:param name="term" as="xs:string"/> | |
<xsl:param name="elements" as="element(tei:index)*"/> | |
<eoa:term key="{$term}"> | |
<eoa:title> | |
<xsl:value-of> | |
<xsl:apply-templates mode="inline" select="tei:term/node()"/> | |
</xsl:value-of> | |
</eoa:title> | |
<xsl:for-each select="$elements[not(tei:index)]"> | |
<xsl:sequence select="eoa:info(concat('adding index element ', tei:term, '!'))"/> | |
<xsl:call-template name="index_entries"/> | |
</xsl:for-each> | |
<xsl:for-each-group | |
select="$elements/tei:index" | |
group-by="if (exists(tei:term/@sortKey)) then tei:term/@sortKey else tei:term/text()" | |
> | |
<xsl:sort select="current-grouping-key()"/> | |
<xsl:call-template name="calc_index_term"> | |
<xsl:with-param name="term" select="current-grouping-key()"/> | |
<xsl:with-param name="elements" select="current-group()"/> | |
</xsl:call-template> | |
</xsl:for-each-group> | |
</eoa:term> | |
</xsl:template> | |
<xsl:template name="index_entries"> | |
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/> | |
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/> | |
<xsl:variable name="dest_id" as="xs:string?"> | |
<xsl:variable name="candidates" as="xs:string*"> | |
<xsl:for-each select="ancestor::tei:*"> | |
<!-- bottom up!: --> | |
<xsl:sort select="count(ancestor::*)" order="descending" data-type="number"/> | |
<xsl:variable name="current_elem"> | |
<xsl:call-template name="eoa:print_elem"/> | |
</xsl:variable> | |
<xsl:sequence select="eoa:debug(concat('trying ', $current_elem))"/> | |
<xsl:variable name="footnote_id" as="xs:string?"> | |
<xsl:call-template name="footnote_id"/> | |
</xsl:variable> | |
<xsl:variable name="container_id" as="xs:string?"> | |
<xsl:call-template name="container_id"/> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$footnote_id"> | |
<xsl:value-of select="$footnote_id"/> | |
</xsl:when> | |
<xsl:when test="$container_id"> | |
<xsl:value-of select="$container_id"/> | |
</xsl:when> | |
</xsl:choose> | |
</xsl:for-each> | |
</xsl:variable> | |
<xsl:sequence select="eoa:debug(concat('candidates ', string-join($candidates, ',')))"/> | |
<xsl:value-of select="if( count($candidates) != 0) then $candidates[1] else ()"/> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="not($dest_id)"> | |
<xsl:sequence select="eoa:warning(concat('paragraph not found for index element ', tei:term, '!'))"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<eoa:entry> | |
<eoa:tei-element> | |
<xsl:copy-of select="."/> | |
</eoa:tei-element> | |
<eoa:link> | |
<eoa:entry> | |
<xsl:value-of select="$series"/> | |
</eoa:entry> | |
<eoa:entry> | |
<xsl:value-of select="$publication_number"/> | |
</eoa:entry> | |
<eoa:entry> | |
<xsl:value-of select="$chapter_nr"/> | |
</eoa:entry> | |
<eoa:entry> | |
<xsl:value-of select="$dest_id"/> | |
</eoa:entry> | |
</eoa:link> | |
</eoa:entry> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |