1<?xml version='1.0' encoding='utf-8'?>
2<!--
3 - Copyright (C) 2011 Google Inc. All rights reserved.
4 -
5 - Redistribution and use in source and binary forms, with or without
6 - modification, are permitted provided that the following conditions are
7 - met:
8 -
9 - # Redistributions of source code must retain the above copyright
10 - notice, this list of conditions and the following disclaimer.
11 - # Redistributions in binary form must reproduce the above
12 - copyright notice, this list of conditions and the following disclaimer
13 - in the documentation and/or other materials provided with the
14 - distribution.
15 - # Neither the name of Google Inc. nor the names of its
16 - contributors may be used to endorse or promote products derived from
17 - this software without specific prior written permission.
18
19 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 -
31 -->
32
33<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
34 <xsl:output method="html"/>
35 <xsl:param name="xml_has_no_style_message"/>
36 <xsl:param name="downArrowBase64"/>
37 <xsl:param name="rightArrowBase64"/>
38
39 <xsl:template match="/">
40 <xsl:call-template name="main"/>
41 </xsl:template>
42
43 <!-- Empty element -->
44 <xsl:template match="*">
45 <div class="line">
46 <span class="webkit-html-tag">
47 <xsl:text><</xsl:text>
48 <xsl:value-of select="name()"/>
49 <xsl:apply-templates select="@*"/>
50 <xsl:text>/></xsl:text>
51 </span>
52 </div>
53 </xsl:template>
54
55 <!-- Element with short text only -->
56 <xsl:template match="*[node()]">
57 <div class="line">
58 <span class="webkit-html-tag">
59 <xsl:text><</xsl:text>
60 <xsl:value-of select="name()"/>
61 <xsl:apply-templates select="@*"/>
62 <xsl:text>></xsl:text>
63 </span>
64
65 <span class="text"><xsl:value-of select="."/></span>
66
67 <span class="webkit-html-tag">
68 <xsl:text></</xsl:text>
69 <xsl:value-of select="name()"/>
70 <xsl:text>></xsl:text>
71 </span>
72 </div>
73 </xsl:template>
74
75 <!-- Collapsable element -->
76 <xsl:template match="*[* or processing-instruction() or comment() or string-length() > 50]">
77 <div class="collapsable">
78 <div class="expanded">
79 <div class="line">
80 <xsl:call-template name="collapse-button"/>
81 <span class="webkit-html-tag">
82 <xsl:text><</xsl:text>
83 <xsl:value-of select="name()"/>
84 <xsl:apply-templates select="@*"/>
85 <xsl:text>></xsl:text>
86 </span>
87 </div>
88
89 <div class="collapsable-content">
90 <xsl:apply-templates/>
91 </div>
92
93 <div class="line">
94 <span class="webkit-html-tag">
95 <xsl:text></</xsl:text>
96 <xsl:value-of select="name()"/>
97 <xsl:text>></xsl:text>
98 </span>
99 </div>
100 </div>
101
102 <div class="collapsed hidden">
103 <div class="line">
104 <xsl:call-template name="expand-button"/>
105 <span class="webkit-html-tag">
106 <xsl:text><</xsl:text>
107 <xsl:value-of select="name()"/>
108 <xsl:apply-templates select="@*"/>
109 <xsl:text>></xsl:text>
110 <xsl:text>...</xsl:text>
111 <xsl:text></</xsl:text>
112 <xsl:value-of select="name()"/>
113 <xsl:text>></xsl:text>
114 </span>
115 </div>
116 </div>
117 </div>
118 </xsl:template>
119
120 <!-- Any attribute -->
121 <xsl:template match="@*">
122 <xsl:text> </xsl:text>
123 <span class="webkit-html-attribute-name"><xsl:value-of select="name()"/></span>
124 <xsl:text>="</xsl:text>
125 <span class="webkit-html-attribute-value"><xsl:value-of select="."/></span>
126 <xsl:text>"</xsl:text>
127 </xsl:template>
128
129 <!-- Short comment -->
130 <xsl:template match="comment()">
131 <div class="line">
132 <span class="webkit-html-comment">
133 <xsl:text><!--</xsl:text>
134 <xsl:value-of select="."/>
135 <xsl:text>--></xsl:text>
136 </span>
137 </div>
138 </xsl:template>
139
140 <!-- Long comment -->
141 <xsl:template match="comment()[string-length() > 50]">
142 <div class="collapsable">
143 <div class="expanded">
144 <div class="line">
145 <xsl:call-template name="collapse-button"/>
146 <span class="webkit-html-comment">
147 <xsl:text><!--</xsl:text>
148 </span>
149 </div>
150
151 <div class="collapsable-content comment">
152 <span class="webkit-html-comment"><xsl:value-of select="."/></span>
153 </div>
154
155 <div class="line">
156 <span class="webkit-html-comment">
157 <xsl:text>--></xsl:text>
158 </span>
159 </div>
160 </div>
161
162 <div class="collapsed hidden">
163 <div class="line">
164 <xsl:call-template name="expand-button"/>
165 <span class="webkit-html-comment">
166 <xsl:text><!--</xsl:text>
167 </span>
168
169 <span class="webkit-html-comment"><xsl:text>...</xsl:text></span>
170
171 <span class="webkit-html-comment">
172 <xsl:text>--></xsl:text>
173 </span>
174 </div>
175 </div>
176 </div>
177 </xsl:template>
178
179 <!-- Short processing instruction -->
180 <xsl:template match="processing-instruction()[name() != 'xml-stylesheet']">
181 <div class="line">
182 <span class="webkit-html-comment">
183 <xsl:text><?</xsl:text>
184 <xsl:value-of select="name()"/>
185 <xsl:text> </xsl:text>
186 <xsl:value-of select="."/>
187 <xsl:text>?></xsl:text>
188 </span>
189 </div>
190 </xsl:template>
191
192 <!-- Long processing instruction -->
193 <xsl:template match="processing-instruction()[(string-length() > 50) and (name() != 'xml-stylesheet')]">
194 <div class="collapsable">
195 <div class="expanded">
196 <div class="line">
197 <xsl:call-template name="collapse-button"/>
198 <span class="webkit-html-comment">
199 <xsl:text><?</xsl:text>
200 <xsl:value-of select="name()"/>
201 <xsl:text> </xsl:text>
202 </span>
203 </div>
204
205 <div class="collapsable-content">
206 <span class="webkit-html-comment"><xsl:value-of select="."/></span>
207 </div>
208
209 <div class="line">
210 <span class="webkit-html-comment">
211 <xsl:text>?></xsl:text>
212 </span>
213 </div>
214 </div>
215 <div class="collapsed hidden">
216 <div class="line">
217 <xsl:call-template name="expand-button"/>
218 <span class="webkit-html-comment">
219 <xsl:text><?</xsl:text>
220 <xsl:value-of select="name()"/>
221 </span>
222
223 <span class="webkit-html-comment"><xsl:text>...</xsl:text></span>
224
225 <span class="webkit-html-comment">
226 <xsl:text>?></xsl:text>
227 </span>
228 </div>
229 </div>
230 </div>
231 </xsl:template>
232
233 <!-- Text node -->
234 <xsl:template match="text()">
235 <xsl:value-of select="."/>
236 </xsl:template>
237
238 <xsl:template name="collapse-button">
239 <span class="button collapse-button" onclick="return collapseButtonClick(this);" onmousedown="return buttonMouseDown();">
240 </span>
241 </xsl:template>
242
243 <xsl:template name="expand-button">
244 <span class="button expand-button" onclick="return expandButtonClick(this);" onmousedown="return buttonMouseDown();">
245 </span>
246 </xsl:template>
247
248 <xsl:template name="main">
249 <html>
250 <head>
251 <xsl:call-template name="style"/>
252 <xsl:call-template name="script"/>
253 </head>
254 <body>
255 <div class="header">
256 <span> <xsl:value-of select="$xml_has_no_style_message"/> </span>
257 <br/>
258 </div>
259
260 <div class="pretty-print">
261 <xsl:apply-templates/>
262 </div>
263 <div> </div>
264 </body>
265 </html>
266 </xsl:template>
267
268 <xsl:template name="script">
269 <script type="text/javascript">
270 <xsl:text>
271 function buttonMouseDown() {
272 // To prevent selection on double click
273 return false;
274 }
275
276 function getElementsByClassName(classname, node, recursive) {
277 var a = [];
278 var re = new RegExp('\\b' + classname + '\\b');
279 var els;
280 if (recursive) {
281 els = node.getElementsByTagName('div');
282 } else {
283 els = node.childNodes;
284 }
285 for(var i = 0,j = els.length; i < j; i++) {
286 if(re.test(els[i].className)) {
287 a.push(els[i]);
288 }
289 }
290 return a;
291 }
292
293 function expandButtonClick(button) {
294 getElementsByClassName('expanded', button.parentNode.parentNode.parentNode, false)[0].className = 'expanded';
295 getElementsByClassName('collapsed', button.parentNode.parentNode.parentNode, false)[0].className = 'collapsed hidden';
296 }
297
298 function collapseButtonClick(button) {
299 getElementsByClassName('collapsed', button.parentNode.parentNode.parentNode, false)[0].className = 'collapsed';
300 getElementsByClassName('expanded', button.parentNode.parentNode.parentNode, false)[0].className = 'expanded hidden';
301 }
302 </xsl:text>
303 </script>
304 </xsl:template>
305
306 <xsl:template name="style">
307 <style type="text/css">
308 div.header {
309 border-bottom: 2px solid black;
310 padding-bottom: 5px;
311 margin: 10px;
312 }
313
314 div.collapsable > div.hidden {
315 display:none;
316 }
317
318 .pretty-print {
319 margin-top: 1em;
320 margin-left: 20px;
321 font-family: monospace;
322 font-size: 13px;
323 }
324
325 .collapsable-content {
326 margin-left: 1em;
327 }
328 .comment {
329 whitespace: pre;
330 }
331
332 .button {
333 -webkit-user-select: none;
334 cursor: pointer;
335 display: inline-block;
336 margin-left: -10px;
337 width: 10px;
338 background-repeat: no-repeat;
339 background-position: left top;
340 vertical-align: bottom;
341 }
342
343 .collapse-button {
344 background-image: url(<xsl:value-of select="$downArrowBase64"/>);
345 height: 10px;
346 }
347
348 .expand-button {
349 background-image: url(<xsl:value-of select="$rightArrowBase64"/>);
350 height: 11px;
351 }
352 </style>
353 </xsl:template>
354</xsl:stylesheet>