Added a selectbox not a file path for XSL. Added upload for managing your XSL. tweake...
[project/xsl_formatter.git] / xsl / mozDss5.xsl
1 <!--\r
2                                                                                 \r
3  ***** BEGIN LICENSE BLOCK *****                                                \r
4    - Version: MPL 1.1/GPL 2.0/LGPL 2.1                                          \r
5    -                                                                            \r
6    - The contents of this file are subject to the Mozilla Public License Version\r
7    - 1.1 (the "License"); you may not use this file except in compliance with   \r
8    - the License. You may obtain a copy of the License at                       \r
9    - http://www.mozilla.org/MPL/                                                \r
10    -                                                                            \r
11    - Software distributed under the License is distributed on an "AS IS" basis, \r
12    - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License   \r
13    - for the specific language governing rights and limitations under the       \r
14    - License.                                                                   \r
15    -                                                                            \r
16    - The Original Code is mozilla.org code.                                     \r
17    -                                                                            \r
18    - The Initial Developer of the Original Code is                              \r
19    - Netscape Communications Corporation.                                       \r
20    - Portions created by the Initial Developer are Copyright (C) 2002           \r
21    - the Initial Developer. All Rights Reserved.                                \r
22    -                                                                            \r
23    - Contributor(s):                                                            \r
24    -   Jonas Sicking <sicking@bigfoot.com> (Original author)                    \r
25    -                                                                            \r
26    - Alternatively, the contents of this file may be used under the terms of    \r
27    - either the GNU General Public License Version 2 or later (the "GPL"), or   \r
28    - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),   \r
29    - in which case the provisions of the GPL or the LGPL are applicable instead \r
30    - of those above. If you wish to allow use of your version of this file only \r
31    - under the terms of either the GPL or the LGPL, and not to allow others to  \r
32    - use your version of this file under the terms of the MPL, indicate your    \r
33    - decision by deleting the provisions above and replace them with the notice \r
34    - and other provisions required by the LGPL or the GPL. If you do not delete \r
35    - the provisions above, a recipient may use your version of this file under  \r
36    - the terms of any one of the MPL, the GPL or the LGPL.                      \r
37    -                                                                            \r
38    - ***** END LICENSE BLOCK *****                                              \r
39 -->\r
40 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
41  >  \r
42   \r
43   <xsl:param name="selectedNodes" select="@comment()"/>\r
44   <xsl:param name="scalarExpr" select="@comment()"/>\r
45 \r
46 <!-- The following is not used because of a bug in Mozilla :( -->\r
47 <!--\r
48   <xsl:key name="kattPref" match="@*" \r
49    use="concat(generate-id(..), '|', substring-before(., ':'))"/>\r
50 -->  \r
51   <xsl:output method="html"/>  \r
52   <xsl:template match="/">    \r
53     <html xmlns="http://www.w3.org/1999/xhtml">      \r
54       <head>        \r
55         <style>\r
56           .mozDss5 {\r
57             font-family: 'Verdana', sans-serif;\r
58             width: 100%;\r
59             margin: 0;\r
60             padding: 0;\r
61           }\r
62           \r
63           \r
64           .mozDss5 img {\r
65             float: left;\r
66             margin: 0.5em;\r
67           }\r
68           \r
69           .mozDss5 table {\r
70             border-spacing: 0;\r
71             margin: 0;\r
72             width:auto;\r
73           }\r
74           \r
75           .mozDss5 td {\r
76             padding: 0;\r
77             border:none;\r
78           }\r
79           \r
80           .mozDss5 .markup {\r
81             color: blue\r
82           }\r
83           \r
84           .mozDss5 .elemname {\r
85             color: #990000;\r
86           }\r
87           \r
88           .mozDss5 .attrname {\r
89             color: #990000;\r
90             font-weight: bold;\r
91           }\r
92           \r
93           .mozDss5 .namespace {\r
94             color: red;\r
95             font-weight: bold;\r
96           }\r
97           .mozDss5 .attrvalue {\r
98             color: black;\r
99             font-weight: bold;\r
100           }\r
101           \r
102           .mozDss5 .text {\r
103             color: black;\r
104             font-weight: bold;\r
105           }\r
106           \r
107           .mozDss5 .indent {\r
108             margin-left: 1em;\r
109           }\r
110           \r
111           .mozDss5 .comment {\r
112             color: #888888;\r
113             font-style: italic;\r
114           }\r
115           \r
116           .mozDss5 .pi {\r
117             color: blue;\r
118           }\r
119           \r
120           .mozDss5 .expander > div {\r
121             width: 1em;\r
122           }\r
123           \r
124           .mozDss5 .expander {\r
125             cursor: default;\r
126             -moz-user-select: none;\r
127             vertical-align: top;\r
128             text-align: center;\r
129             margin: 0 0 0 -1em;\r
130           }\r
131           \r
132           .mozDss5 .expander-closed .expander-content {\r
133             display: none;\r
134           }\r
135           \r
136           .mozDss5 .se  {background-Color:yellow}\r
137         </style>        \r
138         <script>          \r
139           <xsl:comment><![CDATA[\r
140 \r
141 function clicked(event) {\r
142   try {\r
143         var thisNode = event.target;\r
144     var par = event.target.parentNode;\r
145     if (thisNode.nodeName == 'TD' && thisNode.className == 'expander') {\r
146       if (par.parentNode.className == 'expander-closed') {\r
147         par.parentNode.className = '';\r
148         event.target.data = '-';\r
149       }\r
150       else {\r
151         par.parentNode.className = 'expander-closed';\r
152         event.target.data = '+';\r
153       }\r
154     }\r
155   } catch (e) {\r
156   }\r
157 }\r
158 \r
159 ]]></xsl:comment>        \r
160         </script>      \r
161       </head>      \r
162       <body bgcolor="#E9FEFE" ID="theBody" title="{$scalarExpr}" onclick="clicked(event) ">        \r
163         <xsl:apply-templates/>      \r
164       </body>    \r
165     </html>  \r
166   </xsl:template>  \r
167   \r
168   <xsl:template match="*">    \r
169     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
170     \r
171     <div class="indent">      \r
172       <span class="markup">&lt;</span>      \r
173       \r
174       <xsl:variable name="class">\r
175       <xsl:choose>\r
176         <xsl:when test="$belongs = 0">se</xsl:when>\r
177         <xsl:otherwise>elemname</xsl:otherwise> \r
178       </xsl:choose>\r
179       </xsl:variable>     \r
180       \r
181       <span class="{$class}">        \r
182         <xsl:value-of select="name(.)"/>      \r
183       </span>\r
184       \r
185       <xsl:call-template name="findNamespace"/>\r
186                        \r
187       <xsl:apply-templates select="@*"/>      \r
188       <span class="markup">/></span>    \r
189     </div>  \r
190   </xsl:template>  \r
191 \r
192   <xsl:template match="*[text()]">    \r
193     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
194     \r
195     <xsl:variable name="class">\r
196       <xsl:choose>\r
197         <xsl:when test="$belongs = 0">se</xsl:when>\r
198         <xsl:otherwise>elemname</xsl:otherwise> \r
199       </xsl:choose>\r
200     </xsl:variable>     \r
201     \r
202     <div class="indent">      \r
203       <span class="markup">&lt;</span>      \r
204       <span class="{$class}">        \r
205         <xsl:value-of select="name(.)"/>      \r
206       </span>\r
207 \r
208       <xsl:call-template name="findNamespace"/>\r
209                        \r
210       <xsl:apply-templates select="@*"/>      \r
211       <span class="markup">></span>      \r
212       <!--<span class="text">        \r
213         <xsl:value-of select="."/>      -->\r
214         <xsl:apply-templates/>\r
215       <!--</span>-->      \r
216       <span class="markup">&lt;/</span>      \r
217       <span class="elemname">        \r
218         <xsl:value-of select="name(.)"/>      \r
219       </span>      \r
220       <span class="markup">></span>    \r
221     </div>  \r
222   </xsl:template>  \r
223   \r
224   <xsl:template match="*[* or processing-instruction() or comment() \r
225                          or string-length(text()) > 50]" priority="10">    \r
226     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
227     \r
228     <xsl:variable name="class">\r
229       <xsl:choose>\r
230         <xsl:when test="$belongs = 0">se</xsl:when>\r
231         <xsl:otherwise>elemname</xsl:otherwise> \r
232       </xsl:choose>\r
233     </xsl:variable>     \r
234     \r
235 \r
236     <table class="mozDss5">      \r
237       <tr>        \r
238         <td class="expander">\r
239           -\r
240           <div/>        \r
241         </td>        \r
242         <td>          \r
243           <span class="markup">&lt;</span>          \r
244           <span class="{$class}">            \r
245             <xsl:value-of select="name(.)"/>          \r
246           </span>          \r
247           <xsl:call-template name="findNamespace"/>\r
248           <xsl:apply-templates select="@*"/>          \r
249           <span class="markup">></span>          \r
250           <div class="expander-content">            \r
251             <xsl:apply-templates/>          \r
252           </div>          \r
253           <span class="markup">&lt;/</span>          \r
254           <span class="elemname">            \r
255             <xsl:value-of select="name(.)"/>          \r
256           </span>          \r
257           <span class="markup">></span>        \r
258         </td>      \r
259       </tr>    \r
260     </table>  \r
261   </xsl:template>  \r
262   <xsl:template match="@*">    \r
263     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
264     \r
265 \r
266     <xsl:variable name="vPos" select="position()"/>\r
267     \r
268     <xsl:variable name="vPref" select="substring-before(name(), ':')"/>\r
269 \r
270     <xsl:if test="$vPref \r
271                and \r
272                   not(../@*[position() &lt; $vPos]\r
273                            [substring-before(name(), ':') \r
274                            = $vPref]\r
275                       )">\r
276       <xsl:call-template name="findNamespace"/>\r
277     </xsl:if>\r
278 \r
279 <!-- The following is not used because of a bug in Mozilla :( -->\r
280 \r
281 <!--\r
282     <xsl:if test=\r
283     "generate-id() \r
284     = \r
285      generate-id(key('kattPref', \r
286                       concat(generate-id(..), '|', substring-before(., ':'))\r
287                      )[1]\r
288                 )">\r
289       <xsl:call-template name="findNamespace"/>\r
290     </xsl:if>\r
291 -->\r
292     <xsl:variable name="class">\r
293       <xsl:choose>\r
294         <xsl:when test="$belongs = 0">se</xsl:when>\r
295         <xsl:otherwise>attrname</xsl:otherwise> \r
296       </xsl:choose>\r
297     </xsl:variable>\r
298     \r
299     <xsl:variable name="class2">\r
300       <xsl:choose>\r
301         <xsl:when test="$belongs = 0">se</xsl:when>\r
302         <xsl:otherwise>markup</xsl:otherwise> \r
303       </xsl:choose>\r
304     </xsl:variable>\r
305     \r
306     <xsl:variable name="class3">\r
307       <xsl:choose>\r
308         <xsl:when test="$belongs = 0">se</xsl:when>\r
309         <xsl:otherwise>attrvalue</xsl:otherwise> \r
310       </xsl:choose>\r
311     </xsl:variable>\r
312     \r
313     <xsl:text> </xsl:text>    \r
314     <span class="{$class}">      \r
315       <xsl:value-of select="name(.)"/>    \r
316     </span>    \r
317     <span class="{$class2}">="</span>    \r
318     <span class="{$class3}">      \r
319       <!-- <xsl:value-of select="."/> -->    \r
320       <xsl:call-template name="replaceAmpersands">\r
321         <xsl:with-param name="vString" select="string(.)"/>\r
322       </xsl:call-template>\r
323     </span>    \r
324     <span class="{$class2}">"</span>  \r
325   </xsl:template>  \r
326   \r
327   <xsl:template match="text()">    \r
328     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
329     \r
330     <xsl:variable name="class">\r
331       <xsl:choose>\r
332         <xsl:when test="$belongs = 0">se</xsl:when>\r
333         <xsl:otherwise>text</xsl:otherwise> \r
334       </xsl:choose>\r
335     </xsl:variable>\r
336     \r
337     <span class="{$class}">        \r
338       <!-- <xsl:value-of select="."/>       -->\r
339       <xsl:call-template name="replaceAmpersands">\r
340         <xsl:with-param name="vString" select="string(.)"/>\r
341       </xsl:call-template>\r
342     </span>    \r
343   </xsl:template>  \r
344   \r
345   <xsl:template match="processing-instruction()">    \r
346     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
347     \r
348     <xsl:variable name="class">\r
349       <xsl:choose>\r
350         <xsl:when test="$belongs = 0">se</xsl:when>\r
351         <xsl:otherwise>indent pi</xsl:otherwise> \r
352       </xsl:choose>\r
353     </xsl:variable>\r
354     \r
355     <div class="{$class}">\r
356 \r
357       &lt;?\r
358       <xsl:value-of select="name(.)"/>      \r
359       <xsl:text> </xsl:text>      \r
360       <xsl:value-of select="."/>\r
361 ?>\r
362     \r
363     </div>  \r
364   </xsl:template>  \r
365 \r
366   <xsl:template match="processing-instruction()[string-length(.) > 50]">    \r
367     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
368     \r
369     <xsl:variable name="class">\r
370       <xsl:choose>\r
371         <xsl:when test="$belongs = 0">se</xsl:when>\r
372         <xsl:otherwise>pi</xsl:otherwise> \r
373       </xsl:choose>\r
374     </xsl:variable>\r
375     \r
376     <xsl:variable name="class2">\r
377       <xsl:choose>\r
378         <xsl:when test="$belongs = 0">se</xsl:when>\r
379         <xsl:otherwise>indent expander-content</xsl:otherwise> \r
380       </xsl:choose>\r
381     </xsl:variable>\r
382     \r
383     <table>      \r
384       <tr>        \r
385         <td class="expander">\r
386           -          \r
387           <div/>        \r
388         </td>        \r
389         <td class="{$class}">\r
390 \r
391           &lt;?\r
392           <xsl:value-of select="name(.)"/>          \r
393           <div class="{$class2}">            \r
394             <xsl:value-of select="."/>          \r
395           </div>          \r
396           <xsl:text>?></xsl:text>        \r
397         </td>      \r
398       </tr>    \r
399     </table>  \r
400   </xsl:template>  \r
401 \r
402   <xsl:template match="comment()">    \r
403     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
404     \r
405     <xsl:variable name="class">\r
406       <xsl:choose>\r
407         <xsl:when test="$belongs = 0">se</xsl:when>\r
408         <xsl:otherwise>comment indent</xsl:otherwise> \r
409       </xsl:choose>\r
410     </xsl:variable>\r
411     \r
412     <div class="{$class}">      \r
413       &lt;!--\r
414       <xsl:value-of select="."/>\r
415       -->    \r
416     </div>  \r
417   </xsl:template>  \r
418 \r
419   <xsl:template match="comment()[string-length(.) > 50]">    \r
420     <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>\r
421     \r
422     <xsl:variable name="class">\r
423       <xsl:choose>\r
424         <xsl:when test="$belongs = 0">se</xsl:when>\r
425         <xsl:otherwise>comment</xsl:otherwise> \r
426       </xsl:choose>\r
427     </xsl:variable>\r
428     \r
429     <xsl:variable name="class2">\r
430       <xsl:choose>\r
431         <xsl:when test="$belongs = 0">se</xsl:when>\r
432         <xsl:otherwise>indent expander-content</xsl:otherwise> \r
433       </xsl:choose>\r
434     </xsl:variable>\r
435     \r
436     <table>      \r
437       <tr>        \r
438         <td class="expander">\r
439           -          \r
440           <div/>        \r
441         </td>        \r
442         <td class="{$class}">          \r
443           &lt;!--            \r
444           <div class="{$class2}">              \r
445             <xsl:value-of select="."/>            \r
446           </div>          \r
447           -->        \r
448         </td>      \r
449       </tr>    \r
450     </table>  \r
451   </xsl:template>\r
452   \r
453   <xsl:template name="findNamespace">\r
454   \r
455     <xsl:variable name="vName" select="substring-before(name(), ':')"/>\r
456     <xsl:variable name="vUri" select="namespace-uri(.)"/>\r
457 \r
458     <xsl:variable name="vAncestNamespace">\r
459       <xsl:call-template name="findAncNamespace">\r
460         <xsl:with-param name="pName" select="$vName"/>\r
461         <xsl:with-param name="pUri" select="$vUri"/>\r
462       </xsl:call-template>\r
463     </xsl:variable>\r
464 \r
465     <xsl:if test="not(number($vAncestNamespace))">\r
466       <xsl:if test="namespace-uri()\r
467                   or\r
468                     not(generate-id() \r
469                        = \r
470                         generate-id(../@*[name() \r
471                                          = \r
472                                           name(current())]\r
473                                     )\r
474                         )">\r
475         <xsl:if test="parent::* or namespace-uri() or contains(name(), ':')">\r
476           <xsl:text> </xsl:text>    \r
477           <span class="namespace">      \r
478             <xsl:value-of select="'xmlns'"/>\r
479             <xsl:if test="contains(name(), ':')">\r
480               <xsl:value-of select="concat(':', $vName)"/>\r
481             </xsl:if>\r
482           </span>    \r
483           <span class="markup">="</span>    \r
484           <span class="namespace">      \r
485             <xsl:value-of select="namespace-uri()"/>    \r
486           </span>    \r
487           <span class="markup">"</span> \r
488         </xsl:if> \r
489       </xsl:if>\r
490     </xsl:if>\r
491   </xsl:template>\r
492   \r
493   <xsl:template name="findAncNamespace">\r
494     <xsl:param name="pNode" select="."/>\r
495     <xsl:param name="pName" select="substring-before(name(), ':')"/>\r
496     <xsl:param name="pUri" select="namespace-uri(.)"/>\r
497    \r
498      <xsl:choose>\r
499       <xsl:when test="not($pNode/parent::*) \r
500                      and not($pName) and not($pUri)">1</xsl:when>\r
501       <xsl:when test="not($pNode/parent::*)">0</xsl:when>\r
502       <xsl:otherwise>\r
503         <xsl:variable name="vSamePrefs" \r
504         select="number($pName\r
505                       = substring-before(name($pNode/..), ':')\r
506                       )"/>\r
507                       \r
508         <xsl:variable name="vSameUris" \r
509          select="number($pUri  = namespace-uri($pNode/..))"/>\r
510                       \r
511         <xsl:choose>\r
512           <xsl:when test="$vSamePrefs and not($vSameUris)">0</xsl:when>\r
513           <xsl:when test="not($vSamePrefs)">\r
514             <xsl:call-template name="findAncNamespace">\r
515               <xsl:with-param name="pNode" select="$pNode/.."/>\r
516               <xsl:with-param name="pName" select="$pName"/>\r
517               <xsl:with-param name="pUri" select="$pUri"/>\r
518             </xsl:call-template>\r
519           </xsl:when>\r
520            <xsl:otherwise>1</xsl:otherwise>\r
521         </xsl:choose>\r
522       </xsl:otherwise>\r
523     </xsl:choose>\r
524     \r
525   </xsl:template>\r
526   \r
527   <xsl:template name="replaceAmpersands">\r
528     <xsl:param name="vString"/>\r
529    \r
530    <xsl:variable name="vAmp">&amp;</xsl:variable>\r
531    \r
532    <xsl:choose>\r
533    <xsl:when test="contains($vString, $vAmp)">\r
534      <xsl:value-of select="substring-before($vString, $vAmp)"/>\r
535      <xsl:value-of select="concat($vAmp, 'amp;')"/>\r
536      <xsl:call-template name="replaceAmpersands">\r
537        <xsl:with-param name="vString" \r
538        select="substring-after($vString, $vAmp)"/>\r
539      </xsl:call-template>\r
540    </xsl:when>\r
541    <xsl:otherwise>\r
542      <xsl:value-of select="$vString"/>\r
543    </xsl:otherwise>\r
544    </xsl:choose>\r
545    \r
546   </xsl:template>\r
547 </xsl:stylesheet>