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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- XSLT stylesheet to pretty print grammar.xml
usage:
java -jar saxon8.jar grammar.xml print.xsl
-->
<xsl:output method="html" encoding="UTF-8" indent="no" />
<xsl:template match="text()" />
<xsl:template match="*">
<xsl:apply-templates select="*">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="//category">
<xsl:variable name="category_name" select="@name"/>
<xsl:variable name="cat_id" select="generate-id()"/>
<xsl:element name="div">
<xsl:attribute name="id"><xsl:copy-of select="$cat_id"/></xsl:attribute>
<xsl:attribute name="style">display:none</xsl:attribute>
<h4>
<xsl:element name="a">
<xsl:attribute name="href">javascript:;</xsl:attribute>
<xsl:attribute name="onmousedown">toggleDiv('<xsl:copy-of select="$cat_id"/>');</xsl:attribute>
<xsl:value-of select="$category_name"/>
</xsl:element>
(<xsl:value-of select="count(rule[@id!=''])+count(rulegroup[@id!=''])"/>)
</h4>
<ol>
<xsl:apply-templates select="*">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</ol>
</xsl:element>
<h4>
<xsl:element name="a">
<xsl:attribute name="href">javascript:;</xsl:attribute>
<xsl:attribute name="onmousedown">toggleDiv('<xsl:copy-of select="$cat_id"/>');</xsl:attribute>
<xsl:value-of select="$category_name"/>
</xsl:element>
(<xsl:value-of select="count(rule[@id!=''])+count(rulegroup[@id!=''])"/>)
</h4>
</xsl:template>
<xsl:template match="//rule[@id!='']">
<li>
<xsl:value-of select="@name" />
</li>
<ul>
<xsl:apply-templates select="*" />
</ul>
</xsl:template>
<xsl:template match="//rulegroup">
<li>
<xsl:value-of select="@name" />
</li>
<ul>
<xsl:apply-templates select="*" />
</ul>
</xsl:template>
<xsl:template match="//rule/example[@type='incorrect']">
<li>
<xsl:apply-templates select="*|text()" /> <br/>
<xsl:if test="@correction !=''">
<xsl:choose>
<xsl:when test="not(contains(@correction, '|')) and not(contains(../message/text(), '\')) and count(../message/text()) < 3">
<xsl:copy-of select="../message/text()[1]"/>
<strong style="color: #339900;"><xsl:value-of select="@correction"/></strong>
<xsl:copy-of select="../message/text()[2]"/>
</xsl:when>
<xsl:otherwise>
<!-- two problems: parse correction, i.e., split it on "|"
and replace \1 with ../pattern/token[1]/text()
<xsl:copy-of select="../pattern/token[2]/text()"/>
for now, we simply print "Correction", and skip the message
<xsl:variable name="cor_text" select="substring-before(@correction, '|')"/>
<strong style="color: #339900;">
<xsl:value-of select="$cor_text"/>
</strong>
<xsl:variable name="cor_text" select="substring-after($cor_text,'|')"/>
aaaa <xsl:value-of select="$cor_text"/>
<xsl:if test="contains($cor_text, '|')">
<xsl:variable name="message_cnt" select="$message_cnt + 1"/>
aas
<xsl:copy-of select="../message/text()[$message_cnt]"/>
<xsl:variable name="cor_text" select="substring-before(@correction, '|')"/>
<strong style="color: #339900;">
<xsl:value-of select="$cor_text"/>
</strong>
<xsl:variable name="message_cnt" select="$message_cnt + 1"/>
<xsl:copy-of select="../message/text()[$message_cnt]"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="../message/text()[1]"/>
</xsl:otherwise>
</xsl:choose>
-->
<xsl:choose>
<xsl:when test="//rules[@lang='pl']">Poprawnie: </xsl:when>
<xsl:when test="//rules[@lang='en']">Correctly: </xsl:when>
<xsl:when test="//rules[@lang='de']">Korrekt: </xsl:when>
<xsl:when test="//rules[@lang='fr']">Correctement : </xsl:when>
<xsl:when test="//rules[@lang='nl']">Correct: </xsl:when>
<xsl:when test="//rules[@lang='es']">Correctamente: </xsl:when>
</xsl:choose>
<strong style="color: #339900;">
<xsl:value-of select="@correction"/>
</strong>
<!--
<xsl:variable name="text_count" select="count(../message/text())"/>
<xsl:value-of select="../message/text()[$text_count]"/>
-->
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="//rule/example[@type='incorrect']/text()">
<xsl:copy-of select="." />
</xsl:template>
<xsl:template match="//rule/example[@type='incorrect']/marker">
<strong style="color: rgb(255, 0, 0);">
<xsl:value-of select="./text()" />
</strong>
</xsl:template>
<xsl:template match="//rules">
<html>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<head>
<script language="javascript">
<xsl:text>
function toggleDiv(divid){
if(document.getElementById(divid).style.display == 'none'){
document.getElementById(divid).style.display = 'block';
}else{
document.getElementById(divid).style.display = 'none';
}
}
</xsl:text>
</script>
</head>
<body>
<noscript><p><strong>Note:</strong> this page requires Javascript to work</p></noscript>
<xsl:choose>
<xsl:when test="//rules[@lang='pl']">Łączna liczba reguł: </xsl:when>
<xsl:otherwise>Total number of rules: </xsl:otherwise>
</xsl:choose>
<strong>
<xsl:value-of select="count(//rule)"/>
</strong>
<br/>
<xsl:choose>
<xsl:when test="//rules[@lang='pl']">W tym z podpowiedziami: </xsl:when>
<xsl:otherwise>Rules with suggestions: </xsl:otherwise>
</xsl:choose>
<strong>
<xsl:value-of select="count(//message[suggestion!=''])"/>
</strong>
<br/>
<xsl:choose>
<xsl:when test="//rules[@lang='pl']">Liczba widocznych typów reguł: </xsl:when>
<xsl:otherwise>Total number of visible rule types: </xsl:otherwise>
</xsl:choose>
<strong>
<xsl:value-of select="count(//rule[@id!=''])+count(//rulegroup[@id!=''])"/>
</strong>
<br/>
<xsl:apply-templates select="*">
<xsl:sort select="@name"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|