Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Script for generating xml:id attributes for certain elements
  • Loading branch information
Klaus Thoden committed Jul 11, 2017
1 parent 84bb40d commit 05564d5
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions assign_ids.xsl
@@ -0,0 +1,75 @@
<?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>

0 comments on commit 05564d5

Please sign in to comment.