-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlemmas.xsl
68 lines (64 loc) · 3.16 KB
/
lemmas.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:thl="java:org.thdl.tib.scanner.BasicTibetanTranscriptionConverter" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//entry[wrI]"/> <!-- ignore auxiliaries -->
</xsl:template>
<xsl:template match="entry">
<xsl:variable name="wylie" select="headword/orth[1]"/> <!-- get first headword value -->
<xsl:variable name="lemma">
<xsl:call-template name="toUnicode">
<xsl:with-param name="wylie">
<xsl:value-of select="$wylie"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>་</xsl:text> <!-- add tsheg -->
</xsl:variable>
<xsl:variable name="stems" select="*[starts-with(local-name(.), 'wr')]"/>
<xsl:if test="count($stems) > 0">
<xsl:variable name="suffix">
<xsl:variable name="sameBefore"
select="count(./preceding-sibling::entry[wrI][headword/orth[1]=$wylie])"/>
<xsl:choose>
<xsl:when test="$sameBefore > 0">
<xsl:text>√</xsl:text>
<xsl:value-of select="$sameBefore+1"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="sameAfter"
select="count(./following-sibling::entry[wrI][headword/orth[1]=$wylie])"/>
<xsl:if test="$sameAfter > 0">
<xsl:text>√1</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat($lemma, $suffix)"/>
<xsl:text>	</xsl:text>
<xsl:for-each select="volition/label">
<xsl:value-of select="substring-before(normalize-space(.), ':')"/>
</xsl:for-each>
<xsl:text>	</xsl:text>
<xsl:value-of select="replace(substring-before(substring-after(syntax/text()[2], '['), '.]'), '\.\s+', '-')"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="replace(normalize-space(trans), '\s*Meaning:\s*', '')"/>
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:if test="./auxillary">
<xsl:value-of select="concat($lemma, '√x')"/>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="toUnicode">
<xsl:param name="wylie" select="''"/>
<xsl:choose>
<xsl:when test="ends-with($wylie, 'rd') or ends-with($wylie, 'ld')">
<xsl:value-of select="thl:wylieToUnicode(normalize-space(substring($wylie, 1, string-length($wylie)-1)))"/>
<xsl:value-of select="thl:wylieToUnicode('d')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="thl:wylieToUnicode(normalize-space($wylie))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>