Debian Codegraph @

xsl/group-homographs.xsl

raw symbols SCIP
1 <?xml version='1.0' encoding='UTF-8'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
4 <!--
5
6 $Revision$
7
8 This stylesheet converts a TEI file where homographs are not necessarily
9 grouped by using the 'hom' element into a TEI file, where this grouping exists.
10
11 It is required for conversion to bedic format.
12
13 Grouping is done with the 'hom' element instead of the 'superEntry' element, so
14 the structure can be translated more directly into the bedic-format by the SAX event
15 handlers in tei2dic.py.
16
17 Limitations:
18
19 * entries with multiple orth elements are not supported
20 * very slow, the xsl:sort element might be a solution
21 * pron elements of all but the first homograph are discarded
22
23 -->
24
25
26 <!-- Using the doctype-public and doctype-system properties here is in vain,
27 since TEI needs an internal subset to include optional portions of the TEI DTD -->
28 <xsl:output method="xml" encoding="UTF-8"/>
29
30 <!--
31
32 Since XSL provides no way of outputting an internal DTD subset, we use a wrapper script
33 as suggested in the XSLT Recommendation, 16.1 XML Output Method, which contains the
34 default internal subset and includes the output of this stylesheet via an entity reference:
35
36 1. Do not output the TEI.2 element. If we output it, the wrapper would have leave it out,
37 which would make him non-well formed.
38 2. The wrapper and the output of this stylesheet are then used together.
39 2. Optionally, unwrapping to a single file can be done like this (replace each + by minus signs):
40
41 xmllint ++noent tei-wrapper.xml >unwrapped.tei
42
43 -->
44
45 <!--
46
47 The 'verbose' parameter determines, whether to output informational messages
48 or not. It is off by default. To switch it on using Sablotron, use:
49
50 sabcmd group-homographs.xsl infile.tei >grouped.tei '$verbose=1'
51
52 Though not required, you can explicitly switch it off for example by calling
53 the stylesheet with the Sablotron XSLT processor this way:
54
55 sabcmd group-homographs.xsl infile.tei >grouped.tei '$verbose='
56
57 As the parameter is always handed over as a string, only the empty string will
58 be interpreted as a boolean 'false'.
59
60 -->
61 <xsl:param name="verbose" select="''"/>
62
63 <!-- Do no output the TEI.2 element -->
64 <xsl:template match="/TEI.2">
65 <xsl:apply-templates/>
66 </xsl:template>
67
68 <xsl:template match="entry">
69 <xsl:variable name="myorth" select="form/orth"/>
70 <xsl:variable name="myfollowing" select="following-sibling::entry"/>
71 <xsl:variable name="myfollowinghomographs" select="$myfollowing[form/orth = $myorth]"/>
72 <xsl:choose>
73
74 <!-- if an entry has preceding homographs, skip it,
75 as it has already been processed -->
76 <xsl:when test="preceding-sibling::entry/form/orth = $myorth">
77 <xsl:if test="$verbose">
78 <xsl:message terminate="no">
79 Skipping already handled homograph '<xsl:value-of select="$myorth"/>'.
80 </xsl:message>
81 </xsl:if>
82 </xsl:when>
83
84 <!-- if this entry has homographs after it, group them using the
85 hom element -->
86 <xsl:when test="count($myfollowinghomographs) > 0">
87 <entry><xsl:text>&#xa;</xsl:text>
88 <xsl:text>&#xa; </xsl:text>
89
90 <xsl:if test="$verbose">
91 <xsl:message terminate="no">
92 <xsl:text>Transforming using &lt;hom>: '</xsl:text>
93 <xsl:value-of select="$myorth"/>
94 <xsl:text>' has </xsl:text>
95 <xsl:value-of select="1+count($myfollowinghomographs)"/>
96 <xsl:text> homographs.</xsl:text>
97 </xsl:message>
98 </xsl:if>
99
100 <xsl:if test="count($myorth) > 1">
101 <xsl:message terminate="yes">
102 <xsl:text>Can't handle multiple &lt;orth> elements (yet?): </xsl:text>
103 <xsl:for-each select="$myorth">
104 '<xsl:value-of select="."/>'<xsl:text> </xsl:text>
105 </xsl:for-each>- They should be separated into their own entries.
106 </xsl:message>
107 </xsl:if>
108
109 <xsl:apply-templates select="form"/>
110 <xsl:text>&#xa;</xsl:text>
111
112 <!-- copy the first homograph -->
113 <xsl:text>&#xa; </xsl:text>
114 <hom>
115 <xsl:text>&#xa; </xsl:text>
116 <xsl:apply-templates select="*[name(.) != 'form']"/>
117 <xsl:text>&#xa; </xsl:text>
118 </hom>
119 <xsl:text>&#xa; </xsl:text>
120
121 <!-- copy the following homographs -->
122 <xsl:for-each select="$myfollowinghomographs">
123 <xsl:text>&#xa; </xsl:text>
124 <hom>
125 <xsl:text>&#xa; </xsl:text>
126 <xsl:apply-templates select="*[name(.) != 'form']"/>
127 <xsl:text>&#xa; </xsl:text>
128 </hom>
129 <xsl:text>&#xa; </xsl:text>
130 </xsl:for-each>
131 <xsl:text>&#xa; </xsl:text>
132 </entry>
133 </xsl:when>
134
135 <!-- otherwise is has no homograps and it can be copied -->
136 <xsl:otherwise>
137 <entry>
138 <xsl:apply-templates/>
139 </entry>
140 </xsl:otherwise>
141
142 </xsl:choose>
143 </xsl:template>
144
145 <!-- if no other template matches, copy the encountered attributes and elements -->
146 <xsl:template match='@* | node()'>
147 <xsl:copy><xsl:apply-templates select='@* | node()'/></xsl:copy>
148 </xsl:template>
149
150 </xsl:stylesheet>
151