-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtable.xsl
93 lines (81 loc) · 4.32 KB
/
table.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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ebook [
<!ENTITY sep "	">
]>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="reading" select="document('reading.xml')"/>
<xsl:variable name="measure" select="document('measure.xml')"/>
<xsl:variable name="surname" select="document('surname.xml')"/>
<xsl:variable name="exclamative" select="document('exclamative.xml')"/>
<xsl:variable name="transcription" select="document('transcription.xml')"/>
<xsl:variable name="traditional" select="document('traditional.xml')"/>
<xsl:output method="text" encoding="utf-8"/>
<xsl:template match="/">
<xsl:text>#Character&sep;Keyword&sep;Alternate keywords&sep;Components&sep;Stroke count&sep;Heisig number&sep;Lesson number&sep;Book/page number&sep;Pinyin&sep;Pinyin audio&sep;Jyutping&sep;Jyutping audio&sep;Traditional&sep;Measure word&sep;Surname&sep;Exclamative&sep;Transcription
</xsl:text>
<xsl:apply-templates select="//frame[@number <= 50000]"/>
</xsl:template>
<xsl:template match="frame">
<xsl:variable name="character" select="@character"/>
<xsl:value-of select="@character"/><xsl:text>&sep;</xsl:text>
<xsl:value-of select="@keyword"/><xsl:if test="@pos"> (<xsl:value-of select="@pos"/>)</xsl:if><xsl:text>&sep;</xsl:text>
<xsl:if test="descendant::pself">
<xsl:text>❖ </xsl:text>
<xsl:apply-templates select="descendant::pself" mode="list-of-keywords"/>
</xsl:if><xsl:text>&sep;</xsl:text>
<xsl:apply-templates select="descendant::cite" mode="list-of-keywords"/><xsl:text>&sep;</xsl:text>
<xsl:apply-templates select="strokes" mode="text"/><xsl:text>&sep;</xsl:text>
<xsl:value-of select="@number"/><xsl:text>&sep;</xsl:text>
<xsl:value-of select="ancestor::lesson/@number"/><xsl:text>&sep;</xsl:text>
<xsl:value-of select="ancestor::book/@number"/><xsl:text>.</xsl:text><xsl:value-of select="ancestor::page/@number"/><xsl:text>&sep;</xsl:text>
<xsl:variable name="pinyin" select="$reading/dict/entry[@simplified=$character]/pinyin"/>
<xsl:apply-templates select="$pinyin" mode="text"/><xsl:text>&sep;</xsl:text>
<xsl:apply-templates select="$pinyin" mode="audio"/><xsl:text>&sep;</xsl:text>
<xsl:if test="count($pinyin)=0">
<xsl:message><xsl:value-of select="@character"/><xsl:text> has no pinyin pronunication</xsl:text></xsl:message>
</xsl:if>
<xsl:variable name="jyutping" select="$reading/dict/entry[@simplified=$character]/jyutping"/>
<xsl:apply-templates select="$jyutping" mode="text"/><xsl:text>&sep;</xsl:text>
<xsl:apply-templates select="$jyutping" mode="audio"/><xsl:text>&sep;</xsl:text>
<xsl:if test="count($jyutping)=0">
<xsl:message><xsl:value-of select="@character"/><xsl:text> has no jyutping pronunication</xsl:text></xsl:message>
</xsl:if>
<xsl:apply-templates select="$traditional/dict/entry[@simplified=$character]" mode="traditional"/><xsl:text>&sep;</xsl:text>
<xsl:if test="$measure/dict/entry[@simplified=$character]"><xsl:text>M</xsl:text></xsl:if><xsl:text>&sep;</xsl:text>
<xsl:if test="$surname/dict/entry[@simplified=$character]"><xsl:text>S</xsl:text></xsl:if><xsl:text>&sep;</xsl:text>
<xsl:if test="$exclamative/dict/entry[@simplified=$character]"><xsl:text>E</xsl:text></xsl:if><xsl:text>&sep;</xsl:text>
<xsl:if test="$transcription/dict/entry[@simplified=$character]"><xsl:text>T</xsl:text></xsl:if>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="strokes" mode="text">
<xsl:if test="position() > 1">
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="pinyin" mode="text">
<xsl:if test="position() > 1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:apply-templates select="." mode="number2mark"/>
</xsl:template>
<xsl:template match="jyutping" mode="text">
<xsl:if test="position() > 1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="text()"/>
</xsl:template>
<xsl:template match="pinyin" mode="audio">
<xsl:text>[sound:pinyin-</xsl:text>
<xsl:apply-templates select="." mode="normalize-zero"/>
<xsl:text>.mp3]</xsl:text>
</xsl:template>
<xsl:template match="jyutping" mode="audio">
<xsl:text>[sound:jyutping-</xsl:text>
<xsl:value-of select="text()"/>
<xsl:text>.mp3]</xsl:text>
</xsl:template>
<xsl:template match="entry" mode="traditional">
<xsl:value-of select="@traditional"/>
</xsl:template>
<xsl:include href="util.xsl"/>
</xsl:stylesheet>