build: add runuhttpd sdk target
[project/luci.git] / build / i18n-lua-xhtml1.xsl
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3 Copyright (C) 2008 Alina Friedrichsen <x-alina@gmx.net>
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 SUCH DAMAGE.
25 -->
26
27 <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:i18n="http://luci.freifunk-halle.net/2008/i18n#" xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="i18n h">
28 <xsl:output method="text" encoding="utf-8" media-type="text/x-lua" indent="no"/>
29
30 <xsl:template match="/i18n:msgs">
31 <xsl:apply-templates select="i18n:msg" />
32 </xsl:template>
33
34 <xsl:template match="i18n:msg">
35 <xsl:if test="@xml:id != '' and translate(@xml:id, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz', '') = ''">
36 <xsl:if test="translate(substring(@xml:id, 0, 2), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', '') = ''">
37 <xsl:if test="@xml:id != 'and' and @xml:id != 'break' and @xml:id != 'do' and @xml:id != 'else' and @xml:id != 'elseif' and @xml:id != 'end' and @xml:id != 'false' and @xml:id != 'for' and @xml:id != 'function' and @xml:id != 'if' and @xml:id != 'in' and @xml:id != 'local' and @xml:id != 'nil' and @xml:id != 'not' and @xml:id != 'or' and @xml:id != 'repeat' and @xml:id != 'return' and @xml:id != 'then' and @xml:id != 'true' and @xml:id != 'until' and @xml:id != 'while'">
38 <xsl:value-of select="@xml:id"/>
39 <xsl:text> = '</xsl:text>
40 <xsl:choose>
41 <xsl:when test="@method = 'text'">
42 <xsl:call-template name="escape-lua">
43 <xsl:with-param name="string" select="."/>
44 </xsl:call-template>
45 </xsl:when>
46 <xsl:otherwise>
47 <xsl:apply-templates select="node()" mode="xhtml"/>
48 </xsl:otherwise>
49 </xsl:choose>
50 <xsl:text>'&#10;</xsl:text>
51 </xsl:if>
52 </xsl:if>
53 </xsl:if>
54 </xsl:template>
55
56 <xsl:template match="h:*" priority="-1" mode="xhtml">
57 <xsl:text>&lt;</xsl:text>
58 <xsl:value-of select="local-name(.)"/>
59 <xsl:apply-templates select="@*" mode="xhtml"/>
60 <xsl:text>&gt;</xsl:text>
61 <xsl:apply-templates mode="xhtml"/>
62 <xsl:text>&lt;/</xsl:text>
63 <xsl:value-of select="local-name(.)"/>
64 <xsl:text>&gt;</xsl:text>
65 </xsl:template>
66
67 <xsl:template match="*" priority="-2" mode="xhtml">
68 <xsl:text>&lt;span class=&quot;</xsl:text>
69 <xsl:value-of select="local-name(.)"/>
70 <xsl:text>&quot;</xsl:text>
71 <xsl:apply-templates select="@*" mode="xhtml"/>
72 <xsl:text>&gt;</xsl:text>
73 <xsl:apply-templates mode="xhtml"/>
74 <xsl:text>&lt;/span&gt;</xsl:text>
75 </xsl:template>
76
77 <xsl:template match="h:br" mode="xhtml">
78 <xsl:text>&lt;br</xsl:text>
79 <xsl:apply-templates select="@*" mode="xhtml"/>
80 <xsl:text> /&gt;</xsl:text>
81 </xsl:template>
82
83 <xsl:template match="h:img" mode="xhtml">
84 <xsl:text>&lt;img</xsl:text>
85 <xsl:apply-templates select="@*" mode="xhtml"/>
86 <xsl:text> /&gt;</xsl:text>
87 </xsl:template>
88
89 <xsl:template match="@*" priority="-1" mode="xhtml">
90 <xsl:if test="namespace-uri(.) = '' and local-name(.) != 'lang' or namespace-uri(.) = 'http://www.w3.org/XML/1998/namespace'">
91 <xsl:if test="namespace-uri(..) = 'http://www.w3.org/1999/xhtml' or local-name(.) != 'class'">
92 <xsl:text> </xsl:text>
93 <xsl:if test="namespace-uri(.) = 'http://www.w3.org/XML/1998/namespace'">
94 <xsl:text>xml:</xsl:text>
95 </xsl:if>
96 <xsl:value-of select="local-name(.)"/>
97 <xsl:text>=&quot;</xsl:text>
98 <xsl:variable name="escaped">
99 <xsl:call-template name="escape-lua-xhtml1">
100 <xsl:with-param name="string" select="."/>
101 </xsl:call-template>
102 </xsl:variable>
103 <xsl:value-of select="$escaped"/>
104 <xsl:text>&quot;</xsl:text>
105 </xsl:if>
106 </xsl:if>
107 </xsl:template>
108
109 <xsl:template match="@xml:lang" mode="xhtml">
110 <xsl:variable name="escaped">
111 <xsl:call-template name="escape-lua-xhtml1">
112 <xsl:with-param name="string" select="."/>
113 </xsl:call-template>
114 </xsl:variable>
115 <xsl:text> xml:lang=&quot;</xsl:text>
116 <xsl:value-of select="$escaped"/>
117 <xsl:text>&quot;</xsl:text>
118 <xsl:text> lang=&quot;</xsl:text>
119 <xsl:value-of select="$escaped"/>
120 <xsl:text>&quot;</xsl:text>
121 </xsl:template>
122
123 <xsl:template match="text()" priority="-1" mode="xhtml">
124 <xsl:variable name="escaped">
125 <xsl:call-template name="escape-lua-xhtml1">
126 <xsl:with-param name="string" select="."/>
127 </xsl:call-template>
128 </xsl:variable>
129 <xsl:value-of select="$escaped"/>
130 </xsl:template>
131
132 <xsl:template name="escape-xhtml1">
133 <xsl:param name="string"/>
134 <xsl:variable name="escaped">
135 <xsl:call-template name="replace">
136 <xsl:with-param name="string" select="$string"/>
137 <xsl:with-param name="search" select="'&amp;'"/>
138 <xsl:with-param name="replace" select="'&amp;amp;'"/>
139 </xsl:call-template>
140 </xsl:variable>
141 <xsl:variable name="escaped1">
142 <xsl:call-template name="replace">
143 <xsl:with-param name="string" select="$escaped"/>
144 <xsl:with-param name="search" select="'&quot;'"/>
145 <xsl:with-param name="replace" select="'&amp;quot;'"/>
146 </xsl:call-template>
147 </xsl:variable>
148 <xsl:variable name="escaped2">
149 <xsl:call-template name="replace">
150 <xsl:with-param name="string" select="$escaped1"/>
151 <xsl:with-param name="search" select='"&#39;"'/>
152 <xsl:with-param name="replace" select="'&amp;#39;'"/>
153 </xsl:call-template>
154 </xsl:variable>
155 <xsl:variable name="escaped3">
156 <xsl:call-template name="replace">
157 <xsl:with-param name="string" select="$escaped2"/>
158 <xsl:with-param name="search" select="'&lt;'"/>
159 <xsl:with-param name="replace" select="'&amp;lt;'"/>
160 </xsl:call-template>
161 </xsl:variable>
162 <xsl:call-template name="replace">
163 <xsl:with-param name="string" select="$escaped3"/>
164 <xsl:with-param name="search" select="'&gt;'"/>
165 <xsl:with-param name="replace" select="'&amp;gt;'"/>
166 </xsl:call-template>
167 </xsl:template>
168
169 <xsl:template name="escape-lua">
170 <xsl:param name="string"/>
171 <xsl:variable name="escaped">
172 <xsl:call-template name="replace">
173 <xsl:with-param name="string" select="$string"/>
174 <xsl:with-param name="search" select="'\'"/>
175 <xsl:with-param name="replace" select="'\\'"/>
176 </xsl:call-template>
177 </xsl:variable>
178 <xsl:variable name="escaped1">
179 <xsl:call-template name="replace">
180 <xsl:with-param name="string" select="$escaped"/>
181 <xsl:with-param name="search" select="'&#10;'"/>
182 <xsl:with-param name="replace" select="'\n'"/>
183 </xsl:call-template>
184 </xsl:variable>
185 <xsl:variable name="escaped2">
186 <xsl:call-template name="replace">
187 <xsl:with-param name="string" select="$escaped1"/>
188 <xsl:with-param name="search" select="'&#13;'"/>
189 <xsl:with-param name="replace" select="'\r'"/>
190 </xsl:call-template>
191 </xsl:variable>
192 <xsl:variable name="escaped3">
193 <xsl:call-template name="replace">
194 <xsl:with-param name="string" select="$escaped2"/>
195 <xsl:with-param name="search" select="'&quot;'"/>
196 <xsl:with-param name="replace" select="'\&quot;'"/>
197 </xsl:call-template>
198 </xsl:variable>
199 <xsl:call-template name="replace">
200 <xsl:with-param name="string" select="$escaped3"/>
201 <xsl:with-param name="search" select='"&#39;"'/>
202 <xsl:with-param name="replace" select='"\&#39;"'/>
203 </xsl:call-template>
204 </xsl:template>
205
206 <xsl:template name="escape-lua-xhtml1">
207 <xsl:param name="string"/>
208 <xsl:variable name="escaped">
209 <xsl:call-template name="escape-xhtml1">
210 <xsl:with-param name="string" select="$string"/>
211 </xsl:call-template>
212 </xsl:variable>
213 <xsl:call-template name="escape-lua">
214 <xsl:with-param name="string" select="$escaped"/>
215 </xsl:call-template>
216 </xsl:template>
217
218 <xsl:template name="replace">
219 <xsl:param name="string"/>
220 <xsl:param name="search"/>
221 <xsl:param name="replace"/>
222 <xsl:choose>
223 <xsl:when test="contains($string, $search)">
224 <xsl:value-of select="substring-before($string, $search)"/>
225 <xsl:value-of select="$replace"/>
226 <xsl:call-template name="replace">
227 <xsl:with-param name="string" select="substring-after($string, $search)"/>
228 <xsl:with-param name="search" select="$search"/>
229 <xsl:with-param name="replace" select="$replace"/>
230 </xsl:call-template>
231 </xsl:when>
232 <xsl:otherwise>
233 <xsl:value-of select="$string"/>
234 </xsl:otherwise>
235 </xsl:choose>
236 </xsl:template>
237
238 </xsl:transform>