-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnormalize.xsl
More file actions
57 lines (57 loc) · 2.34 KB
/
normalize.xsl
File metadata and controls
57 lines (57 loc) · 2.34 KB
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
52
53
54
55
56
57
<?xml version="1.1" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xs t" version="3.0" xmlns="http://www.tei-c.org/ns/1.0" xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="no"/>
<xsl:template name="normalize">
<!--
clean up named entities forms
-->
<!--
mode
default : just remove white space
=> create a readable label
"transform" :
lower-case
remove everything that is not [a-z0-9]
=> generate an id
=> compare forms
-->
<xsl:param name="mode"/>
<!-- get all child node text, no white space (excluding abbr, orig and sic if children of choice -->
<xsl:variable name="form">
<xsl:value-of select="normalize-space(string-join(.//text()[not(ancestor::t:abbr[parent::t:choice] or ancestor::t:orig[parent::t:choice] or ancestor::t:sic[parent::t:choice])]))"/>
</xsl:variable>
<xsl:variable name="form">
<xsl:choose>
<xsl:when test="$mode = 'transform'">
<xsl:value-of select="replace(translate(lower-case($form), 'àáâãäåæçčèéêë∈ìíîïòóôõöœûüù∏π', 'aaaaaaacceeeeeiiiioooooouuupp'),'[^a-z0-9]','')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$form"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- if id is one character long, add _ (avoid confusion if we have an alphabetical index with an different url for each letter -->
<xsl:variable name="form">
<xsl:choose>
<xsl:when test="string-length($form) = 1 and $mode = 'transform'">
<xsl:value-of select="concat($form, '_')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$form"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- if id starts with a number, add "n" (xml:id rule) -->
<xsl:variable name="form">
<xsl:choose>
<xsl:when test="matches($form, '^[0-9]') and $mode = 'transform'">
<xsl:value-of select="concat('n', $form)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$form"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$form"/>
</xsl:template>
</xsl:stylesheet>