-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttmtChaines.xsl
162 lines (149 loc) · 7.45 KB
/
ttmtChaines.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?xml version="1.0" encoding="UTF-8"?>
<!--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@Name : ttmtChaines.xsl
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@version : 009
@creaDate : 2013/05/20
@modifDate
@vXslt: 1.0
@autor : Emmanuel Château [email protected]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@use : Cette feuille de style se charge de traiter les chaînes de caractères par le biais d'expressions régulières
@knownBugs : Ne traite pas les singuliers pluriels
@todo :
@historique :
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@gratefulness : http://www.saxonica.com/papers/ideadb-1.1/mhk-paper.xml
http://stackoverflow.com/questions/15593106/extract-text-between-single-quotes-in-xslt
http://www.dpawson.co.uk/xsl/sect2/N7150.html#d9570e1770
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:functx="http://www.metaphoricalweb.org/xmlns/string-utilities">
<xsl:output indent="yes" method="xml" encoding="UTF-8"/>
<xsl:variable name="apos">'</xsl:variable>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:variable name="intermediate">
<xsl:apply-templates mode="phase1"/>
</xsl:variable>
<xsl:apply-templates select="$intermediate" mode="phase2"/>
</xsl:template>
<!-- factoriser avec une règle nommée paramétrisée -->
<!-- glossaire juridique -->
<xsl:template match="hi[@rend='Desgodets_GlossaireJuridique' or @rend='gJ']" mode="phase1">
<xsl:element name="term">
<xsl:attribute name="type">
<xsl:text>gJ</xsl:text>
</xsl:attribute>
<xsl:analyze-string select="." regex="(.*?)\s?\[(.*?)\]\s?" flags="s">
<xsl:matching-substring>
<xsl:attribute name="ref">
<xsl:value-of select="concat( '#' , functx:words-to-camel-case(replace(normalize-unicode(regex-group(2), 'NFKD'), '[̀-ͯ]', '') ) )"/>
</xsl:attribute>
<xsl:value-of select="normalize-space( regex-group(1) )" />
<!-- fournir une valeur de n -->
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:attribute name="ref">
<xsl:value-of select="concat( '#' , functx:words-to-camel-case(replace(normalize-unicode(., 'NFKD'), '[̀-ͯ]', '') ) )"/>
</xsl:attribute>
<xsl:value-of select="." />
</xsl:non-matching-substring>
<xsl:fallback>bug</xsl:fallback>
</xsl:analyze-string>
</xsl:element>
</xsl:template>
<!-- glossaire technique -->
<xsl:template match="hi[@rend='Desgodets_GlossaireTechnique' or @rend='gT']" mode="phase1">
<xsl:element name="term">
<xsl:attribute name="type">
<xsl:text>gT</xsl:text>
</xsl:attribute>
<xsl:analyze-string select="." regex="(.*?)\s?\[(.*?)\]\s?" flags="s">
<xsl:matching-substring>
<xsl:attribute name="ref">
<xsl:value-of
select="concat( '#' , functx:words-to-camel-case(replace(normalize-unicode(regex-group(2), 'NFKD'), '[̀-ͯ]', '') ) )"
/>
</xsl:attribute>
<xsl:value-of select="normalize-space( regex-group(1) )"/>
<!-- fournir une valeur de n -->
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:attribute name="ref">
<xsl:value-of
select="concat( '#' , functx:words-to-camel-case(replace(normalize-unicode(., 'NFKD'), '[̀-ͯ]', '') ) )"
/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
<xsl:fallback>bug</xsl:fallback>
</xsl:analyze-string>
</xsl:element>
</xsl:template>
<!-- glossaire technique et index rerum -->
<xsl:template match="hi[@rend='Desgodets_IndexRerum']" mode="phase1">
<xsl:element name="term">
<xsl:attribute name="type">
<xsl:text>gT</xsl:text>
</xsl:attribute>
<xsl:analyze-string select="." regex="(.*?)\s?\[(.*?)\]\s?" flags="s">
<xsl:matching-substring>
<xsl:attribute name="ref">
<xsl:value-of
select="concat( '#' , functx:words-to-camel-case(replace(normalize-unicode(regex-group(2), 'NFKD'), '[̀-ͯ]', '') ) )"
/>
</xsl:attribute>
<xsl:attribute name="ana">
<xsl:value-of
select="concat( '#i' , functx:words-to-camel-case(replace(normalize-unicode(regex-group(2), 'NFKD'), '[̀-ͯ]', '') ) )"
/>
</xsl:attribute>
<xsl:value-of select="normalize-space( regex-group(1) )"/>
<!-- fournir une valeur de n -->
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:attribute name="ref">
<xsl:value-of
select="concat( '#' , functx:words-to-camel-case(replace(normalize-unicode(., 'NFKD'), '[̀-ͯ]', '') ) )"
/>
</xsl:attribute>
<xsl:attribute name="ana">
<xsl:value-of
select="concat( '#i' , functx:words-to-camel-case(replace(normalize-unicode(., 'NFKD'), '[̀-ͯ]', '') ) )"
/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
<xsl:fallback>bug</xsl:fallback>
</xsl:analyze-string>
</xsl:element>
</xsl:template>
<!--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ copie à l'identique
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-->
<xsl:template match="node()|@*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node()|@*" mode="#current"/>
</xsl:copy>
</xsl:template>
<!--
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ fonctions
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-->
<xsl:function name="functx:words-to-camel-case" as="xs:string">
<xsl:param name="arg" as="xs:string?"/>
<xsl:sequence
select="string-join((tokenize($arg,'\W+')[1], for $word in tokenize($arg,'\W+')[position() > 1]return concat(upper-case(substring($word,1,1)),
substring($word,2))) ,'') "
/>
<!-- j'ai modifié la fonction originale avec \W de manière à tenir compte des apostrophes -->
</xsl:function>
</xsl:stylesheet>