summaryrefslogtreecommitdiffstats
path: root/xsl/mozDss5.xsl
blob: 2ca92f2b888bfa7ccf4b9713edf792975c0a2636 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<!--
                                                                                
 ***** BEGIN LICENSE BLOCK *****                                                
   - Version: MPL 1.1/GPL 2.0/LGPL 2.1                                          
   -                                                                            
   - The contents of this file are subject to the Mozilla Public License Version
   - 1.1 (the "License"); you may not use this file except in compliance with   
   - the License. You may obtain a copy of the License at                       
   - http://www.mozilla.org/MPL/                                                
   -                                                                            
   - Software distributed under the License is distributed on an "AS IS" basis, 
   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License   
   - for the specific language governing rights and limitations under the       
   - License.                                                                   
   -                                                                            
   - The Original Code is mozilla.org code.                                     
   -                                                                            
   - The Initial Developer of the Original Code is                              
   - Netscape Communications Corporation.                                       
   - Portions created by the Initial Developer are Copyright (C) 2002           
   - the Initial Developer. All Rights Reserved.                                
   -                                                                            
   - Contributor(s):                                                            
   -   Jonas Sicking <sicking@bigfoot.com> (Original author)                    
   -                                                                            
   - Alternatively, the contents of this file may be used under the terms of    
   - either the GNU General Public License Version 2 or later (the "GPL"), or   
   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),   
   - in which case the provisions of the GPL or the LGPL are applicable instead 
   - of those above. If you wish to allow use of your version of this file only 
   - under the terms of either the GPL or the LGPL, and not to allow others to  
   - use your version of this file under the terms of the MPL, indicate your    
   - decision by deleting the provisions above and replace them with the notice 
   - and other provisions required by the LGPL or the GPL. If you do not delete 
   - the provisions above, a recipient may use your version of this file under  
   - the terms of any one of the MPL, the GPL or the LGPL.                      
   -                                                                            
   - ***** END LICENSE BLOCK *****                                              
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 >  
  
  <xsl:param name="selectedNodes" select="@comment()"/>
  <xsl:param name="scalarExpr" select="@comment()"/>

<!-- The following is not used because of a bug in Mozilla :( -->
<!--
  <xsl:key name="kattPref" match="@*" 
   use="concat(generate-id(..), '|', substring-before(., ':'))"/>
-->  
  <xsl:output method="html"/>  
  <xsl:template match="/">    
    <html xmlns="http://www.w3.org/1999/xhtml">      
      <head>        
        <style>
          .mozDss5 {
            font-family: 'Verdana', sans-serif;
            width: 100%;
            margin: 0;
            padding: 0;
          }
          
          
          .mozDss5 img {
            float: left;
            margin: 0.5em;
          }
          
          .mozDss5 table {
            border-spacing: 0;
            margin: 0;
            width:auto;
          }
          
          .mozDss5 td {
            padding: 0;
            border:none;
          }
          
          .mozDss5 .markup {
            color: blue
          }
          
          .mozDss5 .elemname {
            color: #990000;
          }
          
          .mozDss5 .attrname {
            color: #990000;
            font-weight: bold;
          }
          
          .mozDss5 .namespace {
            color: red;
            font-weight: bold;
          }
          .mozDss5 .attrvalue {
            color: black;
            font-weight: bold;
          }
          
          .mozDss5 .text {
            color: black;
            font-weight: bold;
          }
          
          .mozDss5 .indent {
            margin-left: 1em;
          }
          
          .mozDss5 .comment {
            color: #888888;
            font-style: italic;
          }
          
          .mozDss5 .pi {
            color: blue;
          }
          
          .mozDss5 .expander > div {
            width: 1em;
          }
          
          .mozDss5 .expander {
            cursor: default;
            -moz-user-select: none;
            vertical-align: top;
            text-align: center;
            margin: 0 0 0 -1em;
          }
          
          .mozDss5 .expander-closed .expander-content {
            display: none;
          }
          
          .mozDss5 .se  {background-Color:yellow}
        </style>        
        <script>          
          <xsl:comment><![CDATA[

function clicked(event) {
  try {
	var thisNode = event.target;
    var par = event.target.parentNode;
    if (thisNode.nodeName == 'TD' && thisNode.className == 'expander') {
      if (par.parentNode.className == 'expander-closed') {
        par.parentNode.className = '';
        event.target.data = '-';
      }
      else {
        par.parentNode.className = 'expander-closed';
        event.target.data = '+';
      }
    }
  } catch (e) {
  }
}

]]></xsl:comment>        
        </script>      
      </head>      
      <body bgcolor="#E9FEFE" ID="theBody" title="{$scalarExpr}" onclick="clicked(event) ">        
        <xsl:apply-templates/>      
      </body>    
    </html>  
  </xsl:template>  
  
  <xsl:template match="*">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <div class="indent">      
      <span class="markup">&lt;</span>      
      
      <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>elemname</xsl:otherwise> 
      </xsl:choose>
      </xsl:variable>     
      
      <span class="{$class}">        
        <xsl:value-of select="name(.)"/>      
      </span>
      
      <xsl:call-template name="findNamespace"/>
                       
      <xsl:apply-templates select="@*"/>      
      <span class="markup">/></span>    
    </div>  
  </xsl:template>  

  <xsl:template match="*[text()]">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>elemname</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>     
    
    <div class="indent">      
      <span class="markup">&lt;</span>      
      <span class="{$class}">        
        <xsl:value-of select="name(.)"/>      
      </span>

      <xsl:call-template name="findNamespace"/>
                       
      <xsl:apply-templates select="@*"/>      
      <span class="markup">></span>      
      <!--<span class="text">        
        <xsl:value-of select="."/>      -->
        <xsl:apply-templates/>
      <!--</span>-->      
      <span class="markup">&lt;/</span>      
      <span class="elemname">        
        <xsl:value-of select="name(.)"/>      
      </span>      
      <span class="markup">></span>    
    </div>  
  </xsl:template>  
  
  <xsl:template match="*[* or processing-instruction() or comment() 
                         or string-length(text()) > 50]" priority="10">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>elemname</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>     
    

    <table class="mozDss5">      
      <tr>        
        <td class="expander">
          -
          <div/>        
        </td>        
        <td>          
          <span class="markup">&lt;</span>          
          <span class="{$class}">            
            <xsl:value-of select="name(.)"/>          
          </span>          
          <xsl:call-template name="findNamespace"/>
          <xsl:apply-templates select="@*"/>          
          <span class="markup">></span>          
          <div class="expander-content">            
            <xsl:apply-templates/>          
          </div>          
          <span class="markup">&lt;/</span>          
          <span class="elemname">            
            <xsl:value-of select="name(.)"/>          
          </span>          
          <span class="markup">></span>        
        </td>      
      </tr>    
    </table>  
  </xsl:template>  
  <xsl:template match="@*">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    

    <xsl:variable name="vPos" select="position()"/>
    
    <xsl:variable name="vPref" select="substring-before(name(), ':')"/>

    <xsl:if test="$vPref 
               and 
                  not(../@*[position() &lt; $vPos]
                           [substring-before(name(), ':') 
                           = $vPref]
                      )">
      <xsl:call-template name="findNamespace"/>
    </xsl:if>

<!-- The following is not used because of a bug in Mozilla :( -->

<!--
    <xsl:if test=
    "generate-id() 
    = 
     generate-id(key('kattPref', 
                      concat(generate-id(..), '|', substring-before(., ':'))
                     )[1]
                )">
      <xsl:call-template name="findNamespace"/>
    </xsl:if>
-->
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>attrname</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <xsl:variable name="class2">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>markup</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <xsl:variable name="class3">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>attrvalue</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <xsl:text> </xsl:text>    
    <span class="{$class}">      
      <xsl:value-of select="name(.)"/>    
    </span>    
    <span class="{$class2}">="</span>    
    <span class="{$class3}">      
      <!-- <xsl:value-of select="."/> -->    
      <xsl:call-template name="replaceAmpersands">
        <xsl:with-param name="vString" select="string(.)"/>
      </xsl:call-template>
    </span>    
    <span class="{$class2}">"</span>  
  </xsl:template>  
  
  <xsl:template match="text()">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>text</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <span class="{$class}">        
      <!-- <xsl:value-of select="."/>       -->
      <xsl:call-template name="replaceAmpersands">
        <xsl:with-param name="vString" select="string(.)"/>
      </xsl:call-template>
    </span>    
  </xsl:template>  
  
  <xsl:template match="processing-instruction()">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>indent pi</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <div class="{$class}">

      &lt;?
      <xsl:value-of select="name(.)"/>      
      <xsl:text> </xsl:text>      
      <xsl:value-of select="."/>
?>
    
    </div>  
  </xsl:template>  

  <xsl:template match="processing-instruction()[string-length(.) > 50]">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>pi</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <xsl:variable name="class2">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>indent expander-content</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <table>      
      <tr>        
        <td class="expander">
          -          
          <div/>        
        </td>        
        <td class="{$class}">

          &lt;?
          <xsl:value-of select="name(.)"/>          
          <div class="{$class2}">            
            <xsl:value-of select="."/>          
          </div>          
          <xsl:text>?></xsl:text>        
        </td>      
      </tr>    
    </table>  
  </xsl:template>  

  <xsl:template match="comment()">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>comment indent</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <div class="{$class}">      
      &lt;!--
      <xsl:value-of select="."/>
      -->    
    </div>  
  </xsl:template>  

  <xsl:template match="comment()[string-length(.) > 50]">    
    <xsl:variable name="belongs" select="count($selectedNodes|.)-count($selectedNodes)"/>
    
    <xsl:variable name="class">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>comment</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <xsl:variable name="class2">
      <xsl:choose>
        <xsl:when test="$belongs = 0">se</xsl:when>
        <xsl:otherwise>indent expander-content</xsl:otherwise> 
      </xsl:choose>
    </xsl:variable>
    
    <table>      
      <tr>        
        <td class="expander">
          -          
          <div/>        
        </td>        
        <td class="{$class}">          
          &lt;!--            
          <div class="{$class2}">              
            <xsl:value-of select="."/>            
          </div>          
          -->        
        </td>      
      </tr>    
    </table>  
  </xsl:template>
  
  <xsl:template name="findNamespace">
  
    <xsl:variable name="vName" select="substring-before(name(), ':')"/>
    <xsl:variable name="vUri" select="namespace-uri(.)"/>

    <xsl:variable name="vAncestNamespace">
      <xsl:call-template name="findAncNamespace">
        <xsl:with-param name="pName" select="$vName"/>
        <xsl:with-param name="pUri" select="$vUri"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:if test="not(number($vAncestNamespace))">
      <xsl:if test="namespace-uri()
                  or
                    not(generate-id() 
                       = 
                        generate-id(../@*[name() 
                                         = 
                                          name(current())]
                                    )
                        )">
        <xsl:if test="parent::* or namespace-uri() or contains(name(), ':')">
          <xsl:text> </xsl:text>    
          <span class="namespace">      
            <xsl:value-of select="'xmlns'"/>
            <xsl:if test="contains(name(), ':')">
              <xsl:value-of select="concat(':', $vName)"/>
            </xsl:if>
          </span>    
          <span class="markup">="</span>    
          <span class="namespace">      
            <xsl:value-of select="namespace-uri()"/>    
          </span>    
          <span class="markup">"</span> 
        </xsl:if> 
      </xsl:if>
    </xsl:if>
  </xsl:template>
  
  <xsl:template name="findAncNamespace">
    <xsl:param name="pNode" select="."/>
    <xsl:param name="pName" select="substring-before(name(), ':')"/>
    <xsl:param name="pUri" select="namespace-uri(.)"/>
   
     <xsl:choose>
      <xsl:when test="not($pNode/parent::*) 
                     and not($pName) and not($pUri)">1</xsl:when>
      <xsl:when test="not($pNode/parent::*)">0</xsl:when>
      <xsl:otherwise>
        <xsl:variable name="vSamePrefs" 
        select="number($pName
                      = substring-before(name($pNode/..), ':')
                      )"/>
                      
        <xsl:variable name="vSameUris" 
         select="number($pUri  = namespace-uri($pNode/..))"/>
                      
        <xsl:choose>
          <xsl:when test="$vSamePrefs and not($vSameUris)">0</xsl:when>
          <xsl:when test="not($vSamePrefs)">
            <xsl:call-template name="findAncNamespace">
              <xsl:with-param name="pNode" select="$pNode/.."/>
              <xsl:with-param name="pName" select="$pName"/>
              <xsl:with-param name="pUri" select="$pUri"/>
            </xsl:call-template>
          </xsl:when>
           <xsl:otherwise>1</xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
    
  </xsl:template>
  
  <xsl:template name="replaceAmpersands">
    <xsl:param name="vString"/>
   
   <xsl:variable name="vAmp">&amp;</xsl:variable>
   
   <xsl:choose>
   <xsl:when test="contains($vString, $vAmp)">
     <xsl:value-of select="substring-before($vString, $vAmp)"/>
     <xsl:value-of select="concat($vAmp, 'amp;')"/>
     <xsl:call-template name="replaceAmpersands">
       <xsl:with-param name="vString" 
       select="substring-after($vString, $vAmp)"/>
     </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select="$vString"/>
   </xsl:otherwise>
   </xsl:choose>
   
  </xsl:template>
</xsl:stylesheet>