-
Notifications
You must be signed in to change notification settings - Fork 87
/
pnumber.xsl
executable file
·51 lines (47 loc) · 1.86 KB
/
pnumber.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template name="teip">
<xsl:param name="pnumber">0</xsl:param>
<xsl:copy>
<xsl:attribute name="n"><xsl:value-of select="$pnumber"></xsl:value-of></xsl:attribute>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()|comment()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//tei:div[@subtype='chapter']">
<xsl:variable name="pnumber">
<xsl:number value="1" />
</xsl:variable>
<xsl:copy>
<xsl:copy-of select="./@*"></xsl:copy-of>
<xsl:for-each select="node()|comment()">
<xsl:choose>
<xsl:when test="name()='p'">
<xsl:call-template name="teip">
<xsl:with-param name="pnumber" select="count(preceding-sibling::tei:p) + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()|comment()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
<xsl:template match="node()|comment()">
<xsl:copy>
<xsl:apply-templates select="./@*"/>
<xsl:apply-templates select="node()|comment()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>