Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
a script taken from the ECHO workflow project
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-content/browser/digitizing-tools/scripts/share/xslFiles/generateId.xsl
and modified for TEI purposes
-->
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*:body//*:p|*:head|*:div|*:table|*:figure|*:formula">
<xsl:variable name="elemName" select="name()"/>
<xsl:variable name="divLevel" select="@type"/>
<xsl:variable name="docPos">
<xsl:choose>
<xsl:when test="$elemName = 'p'">
<xsl:value-of select="count(./preceding::*:p) + 1"/>
</xsl:when>
<xsl:when test="$elemName = 'head'">
<xsl:value-of select="count(./preceding::*:head) + 1"/>
</xsl:when>
<!-- <xsl:when test="$elemName = 'div'"> -->
<!-- </xsl:when> -->
<!-- part chapter section subsection subsubsection -->
<xsl:when test="$divLevel = 'part'">
<xsl:value-of select="count(./preceding::*:div/@type='part') + 1"/>
</xsl:when>
<xsl:when test="$divLevel = 'chapter'">
<xsl:value-of select="count(./preceding::*:div) + 1"/>
</xsl:when>
<xsl:when test="$divLevel = 'section'">
<!-- <xsl:value-of select="count(./preceding::*:div/@type='section') + 1"/> -->
<xsl:value-of select="count(./preceding::*:div) + 1"/>
</xsl:when>
<xsl:when test="$divLevel = 'subsection'">
<xsl:value-of select="count(./preceding::*:div/@type='subsection') + 1"/>
</xsl:when>
<xsl:when test="$divLevel = 'subsubsection'">
<xsl:value-of select="count(./preceding::*:div/@type='subsubsection') + 1"/>
</xsl:when>
<xsl:when test="$elemName = 'table'">
<xsl:value-of select="count(./preceding::*:table) + 1"/>
</xsl:when>
<xsl:when test="$elemName = 'figure'">
<xsl:value-of select="count(./preceding::*:figure) + 1"/>
</xsl:when>
<xsl:when test="$elemName = 'formula'">
<xsl:value-of select="count(./preceding::*:formula) + 1"/>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="xml:id">
<xsl:choose>
<xsl:when test="$elemName = 'div'">
<xsl:value-of select="concat(replace($divLevel, 'section', 'sec'), $docPos)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($elemName, $docPos)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>