comparison software/mpdl-services/mpiwg-mpdl-cms/src/de/mpg/mpiwg/berlin/mpdl/cms/transform/pageXhtml.xsl @ 23:e845310098ba

diverse Korrekturen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Nov 2012 12:35:19 +0100
parents
children
comparison
equal deleted inserted replaced
22:6a45a982c333 23:e845310098ba
1 <?xml version="1.0"?>
2 <xsl:stylesheet version="2.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:xlink="http://www.w3.org/1999/xlink"
5 xmlns:xs="http://www.w3.org/2001/XMLSchema"
6 xmlns:functx="http://www.functx.com"
7 xmlns:saxon="http://saxon.sf.net/"
8 xmlns:dc="http://purl.org/dc/elements/1.1/"
9 xmlns:dcterms="http://purl.org/dc/terms"
10 xmlns:math="http://www.w3.org/1998/Math/MathML"
11 xmlns:svg="http://www.w3.org/2000/svg"
12 xmlns:xhtml="http://www.w3.org/1999/xhtml"
13 exclude-result-prefixes="xsl xlink xs functx saxon dc dcterms math svg xhtml"
14 >
15
16 <xsl:output method="xhtml" encoding="utf-8"/>
17
18 <xsl:param name="echoFiguresDir"></xsl:param>
19 <xsl:param name="echoPageImgDir"></xsl:param>
20
21 <xsl:variable name="dictionaryServiceName" select="'http://mpdl-service.mpiwg-berlin.mpg.de/mpiwg-mpdl-lt-web/lt/GetDictionaryEntries'"/>
22
23 <xsl:template match="*:html">
24 <xsl:apply-templates/>
25 </xsl:template>
26
27 <xsl:template match="body">
28 <xsl:apply-templates mode="html"/>
29 </xsl:template>
30
31 <!-- html mode: transform html texts -->
32 <xsl:template match="@*|node()" mode="html">
33 <xsl:copy>
34 <xsl:apply-templates select="@*|node()" mode="html"/>
35 </xsl:copy>
36 </xsl:template>
37
38 <xsl:template match="s" mode="html">
39 <xsl:apply-templates select="."/>
40 </xsl:template>
41
42 <xsl:template match="w" mode="html">
43 <xsl:apply-templates select="."/>
44 </xsl:template>
45
46
47 <xsl:template match="*:expan|*:emph|*:q|*:quote|*:blockquote|*:set-off|*:reg|*:var|*:num|*:figure">
48 <span>
49 <xsl:attribute name="class"><xsl:value-of select="name()"/></xsl:attribute>
50 <xsl:copy-of select="@*"/>
51 <xsl:apply-templates/>
52 </span>
53 </xsl:template>
54
55 <xsl:template match="*:div">
56 <xsl:if test="node() or normalize-space()"> <!-- test: contains nodes or is not empty -->
57 <div>
58 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
59 <xsl:attribute name="class"><xsl:value-of select="'div'"/></xsl:attribute>
60 <xsl:apply-templates/>
61 </div>
62 </xsl:if>
63 </xsl:template>
64
65 <xsl:template match="*:p">
66 <div>
67 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
68 <xsl:attribute name="class"><xsl:value-of select="'p'"/></xsl:attribute>
69 <xsl:apply-templates/>
70 </div>
71 </xsl:template>
72
73 <xsl:template match="pb">
74 <xsl:variable name="number" select="count(./preceding::*:pb) + 1"/>
75 <xsl:variable name="file" select="$number"/>
76 <span>
77 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
78 <xsl:attribute name="class"><xsl:value-of select="'pb'"/></xsl:attribute>
79 <span>
80 <xsl:attribute name="class"><xsl:value-of select="'src'"/></xsl:attribute>
81 <xsl:attribute name="title"><xsl:value-of select="concat('pageimg/', string($file))"/></xsl:attribute>
82 <span>
83 <xsl:attribute name="class"><xsl:value-of select="'n'"/></xsl:attribute>
84 <xsl:value-of select="$number"/>
85 </span>
86 </span>
87 </span>
88 </xsl:template>
89
90 <xsl:template match="*:head">
91 <div>
92 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
93 <xsl:attribute name="class"><xsl:value-of select="'head bf'"/></xsl:attribute>
94 <xsl:apply-templates/>
95 </div>
96 </xsl:template>
97
98 <!-- MathML -->
99 <xsl:template match="math:*">
100 <xsl:element name="{name()}" namespace="">
101 <xsl:copy-of select="@*"/>
102 <xsl:apply-templates/>
103 </xsl:element>
104 </xsl:template>
105
106 <!-- SVG -->
107 <xsl:template match="svg:*">
108 <xsl:element name="{name()}" namespace="">
109 <xsl:copy-of select="@*"/>
110 <xsl:apply-templates/>
111 </xsl:element>
112 </xsl:template>
113
114 <xsl:template match="*:lb">
115 <br>
116 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
117 <xsl:attribute name="class"><xsl:value-of select="'lb'"/></xsl:attribute>
118 </br>
119 </xsl:template>
120
121 <xsl:template match="*:cb">
122 <br>
123 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
124 <xsl:attribute name="class"><xsl:value-of select="'cb'"/></xsl:attribute>
125 </br>
126 </xsl:template>
127
128 <xsl:template match="br">
129 <br>
130 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
131 <xsl:attribute name="class"><xsl:value-of select="'br'"/></xsl:attribute>
132 </br>
133 </xsl:template>
134
135 <xsl:template match="note">
136 <span>
137 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
138 <xsl:attribute name="class"><xsl:value-of select="'note'"/></xsl:attribute>
139 <xsl:apply-templates/>
140 </span>
141 </xsl:template>
142
143 <xsl:template match="foreign">
144 <xsl:variable name="lang" select="@lang"/>
145 <xsl:variable name="xmllang" select="@xml:lang"/>
146 <xsl:variable name="language">
147 <xsl:choose>
148 <xsl:when test="not(empty($xmllang))"><xsl:value-of select="$xmllang"/></xsl:when>
149 <xsl:when test="not(empty($lang))"><xsl:value-of select="$lang"/></xsl:when>
150 <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
151 </xsl:choose>
152 </xsl:variable>
153 <span>
154 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
155 <xsl:attribute name="class"><xsl:value-of select="concat('foreign ', $language)"/></xsl:attribute>
156 <xsl:apply-templates/>
157 </span>
158 </xsl:template>
159
160 <xsl:template match="gap">
161 <span>
162 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
163 <xsl:attribute name="class"><xsl:value-of select="'gap'"/></xsl:attribute>
164 <xsl:if test="not(empty(@extent))"><span class="extent"><xsl:value-of select="string(@extent)"/></span></xsl:if>
165 <xsl:apply-templates/>
166 </span>
167 </xsl:template>
168
169 <!-- XHTML: remove the xhtml namespace -->
170 <xsl:template match="xhtml:*">
171 <xsl:variable name="hasLabel" select="string(@xlink:label) != ''"/>
172 <xsl:variable name="isTable" select="name() = 'table'"/>
173 <xsl:choose>
174 <xsl:when test="(not($hasLabel)) or ($isTable and $hasLabel)">
175 <xsl:element name="{name()}" namespace="">
176 <xsl:copy-of select="@*"/>
177 <xsl:apply-templates/>
178 </xsl:element>
179 </xsl:when>
180 <xsl:otherwise></xsl:otherwise>
181 </xsl:choose>
182 </xsl:template>
183
184 <xsl:template match="s">
185 <span>
186 <xsl:if test="not(empty(@xml:id))"><xsl:attribute name="id"><xsl:value-of select="@xml:id"/></xsl:attribute></xsl:if>
187 <xsl:attribute name="class"><xsl:value-of select="'s'"/></xsl:attribute>
188 <xsl:apply-templates/>
189 </span>
190 </xsl:template>
191
192 <!-- words -->
193 <xsl:template match="*:w">
194 <xsl:variable name="wordLanguage" select="@lang"/>
195 <xsl:variable name="form" select="encode-for-uri(string(@form))"/>
196 <xsl:variable name="dictionary" select="string(@dictionary)"/>
197 <xsl:variable name="displayWordOrig">
198 <xsl:choose>
199 <xsl:when test="not(empty(*:orig))"><xsl:apply-templates select="*:orig/node()"/></xsl:when>
200 <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
201 </xsl:choose>
202 </xsl:variable>
203 <xsl:variable name="displayWordReg">
204 <xsl:choose>
205 <xsl:when test="not(empty(*:reg))"><xsl:apply-templates select="*:reg/node()"/></xsl:when>
206 <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
207 </xsl:choose>
208 </xsl:variable>
209 <xsl:variable name="displayWordNorm">
210 <xsl:choose>
211 <xsl:when test="not(empty(*:norm))"><xsl:apply-templates select="*:norm/node()"/></xsl:when>
212 <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
213 </xsl:choose>
214 </xsl:variable>
215 <xsl:variable name="displayWordUrlEncoded" select="encode-for-uri($displayWordOrig)"/>
216 <xsl:variable name="dictionaryPart">
217 <xsl:choose>
218 <xsl:when test="$dictionary = 'true'">
219 <a class="dictionary">
220 <xsl:attribute name="href"><xsl:value-of select="concat($dictionaryServiceName, '?query=', $form, '&amp;queryDisplay=', $displayWordUrlEncoded, '&amp;language=', $wordLanguage, '&amp;outputFormat=html', '&amp;outputType=morphCompact&amp;outputType=dictFull')"/></xsl:attribute>
221 <span class="orig"><xsl:sequence select="$displayWordOrig"/></span>
222 <span class="reg"><xsl:sequence select="$displayWordReg"/></span>
223 <span class="norm"><xsl:sequence select="$displayWordNorm"/></span>
224 </a>
225 </xsl:when>
226 <xsl:otherwise>
227 <span class="dictionary">
228 <span class="orig"><xsl:sequence select="$displayWordOrig"/></span>
229 <span class="reg"><xsl:sequence select="$displayWordReg"/></span>
230 <span class="norm"><xsl:sequence select="$displayWordNorm"/></span>
231 </span>
232 </xsl:otherwise>
233 </xsl:choose>
234 </xsl:variable>
235 <span class="w">
236 <xsl:sequence select="$dictionaryPart"/>
237 <span class="nodictionary orig"><xsl:sequence select="$displayWordOrig"/></span>
238 <span class="nodictionary reg"><xsl:sequence select="$displayWordReg"/></span>
239 <span class="nodictionary norm"><xsl:sequence select="$displayWordNorm"/></span>
240 </span>
241 </xsl:template>
242
243 <xsl:template match="*:hi">
244 <xsl:choose>
245 <xsl:when test="@type = 'elem'">
246 <div>
247 <xsl:attribute name="class"><xsl:value-of select="concat('highlight ', @type)"/></xsl:attribute>
248 <xsl:apply-templates/>
249 </div>
250 </xsl:when>
251 <xsl:otherwise>
252 <span>
253 <xsl:attribute name="class"><xsl:value-of select="concat('highlight ', @type)"/></xsl:attribute>
254 <xsl:apply-templates/>
255 </span>
256 </xsl:otherwise>
257 </xsl:choose>
258 </xsl:template>
259
260 </xsl:stylesheet>