Project

General

Profile

1
<?xml version="1.0"?>
2
<?xml-stylesheet type="text/xsl" href="defaultss.xsl"?>
3
<!--
4
  IE5 default style sheet, provides a view of any XML document
5
  and provides the following features:
6
  - auto-indenting of the display, expanding of entity references
7
  - click or tab/return to expand/collapse
8
  - color coding of markup
9
  - color coding of recognized namespaces - xml, xmlns, xsl, dt
10
  
11
  This style sheet is available in IE5 in a compact form at the URL
12
  "res://msxml.dll/DEFAULTSS.xsl".  This version differs only in the
13
  addition of comments and whitespace for readability.
14
  
15
  Author:  Jonathan Marsh (jmarsh@microsoft.com)
16
-->
17

    
18
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
19
                xmlns:dt="urn:schemas-microsoft-com:datatypes"
20
                xmlns:d2="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
21

    
22
<xsl:template match="/">
23
  <HTML>
24
    <HEAD>
25
      <STYLE>
26
        BODY {font:x-small 'Verdana'; margin-right:1.5em}
27
      <!-- container for expanding/collapsing content -->
28
        .c  {cursor:hand}
29
      <!-- button - contains +/-/nbsp -->
30
        .b  {color:red; font-family:'Courier New'; font-weight:bold; text-decoration:none}
31
      <!-- element container -->
32
        .e  {margin-left:1em; text-indent:-1em; margin-right:1em}
33
      <!-- comment or cdata -->
34
        .k  {margin-left:1em; text-indent:-1em; margin-right:1em}
35
      <!-- tag -->
36
        .t  {color:#990000}
37
      <!-- tag in xsl namespace -->
38
        .xt {color:#990099}
39
      <!-- attribute in xml or xmlns namespace -->
40
        .ns {color:red}
41
      <!-- attribute in dt namespace -->
42
        .dt {color:green}
43
      <!-- markup characters -->
44
        .m  {color:blue}
45
      <!-- text node -->
46
        .tx {font-weight:bold}
47
      <!-- multi-line (block) cdata -->
48
        .db {text-indent:0px; margin-left:1em; margin-top:0px; margin-bottom:0px;
49
             padding-left:.3em; border-left:1px solid #CCCCCC; font:small Courier}
50
      <!-- single-line (inline) cdata -->
51
        .di {font:small Courier}
52
      <!-- DOCTYPE declaration -->
53
        .d  {color:blue}
54
      <!-- pi -->
55
        .pi {color:blue}
56
      <!-- multi-line (block) comment -->
57
        .cb {text-indent:0px; margin-left:1em; margin-top:0px; margin-bottom:0px;
58
             padding-left:.3em; font:small Courier; color:#888888}
59
      <!-- single-line (inline) comment -->
60
        .ci {font:small Courier; color:#888888}
61
        PRE {margin:0px; display:inline}
62
      </STYLE>
63

    
64
      <SCRIPT><xsl:comment><![CDATA[
65
        // Detect and switch the display of CDATA and comments from an inline view
66
        //  to a block view if the comment or CDATA is multi-line.
67
        function f(e)
68
        {
69
          // if this element is an inline comment, and contains more than a single
70
          //  line, turn it into a block comment.
71
          if (e.className == "ci") {
72
            if (e.children(0).innerText.indexOf("\n") > 0)
73
              fix(e, "cb");
74
          }
75
          
76
          // if this element is an inline cdata, and contains more than a single
77
          //  line, turn it into a block cdata.
78
          if (e.className == "di") {
79
            if (e.children(0).innerText.indexOf("\n") > 0)
80
              fix(e, "db");
81
          }
82
          
83
          // remove the id since we only used it for cleanup
84
          e.id = "";
85
        }
86
        
87
        // Fix up the element as a "block" display and enable expand/collapse on it
88
        function fix(e, cl)
89
        {
90
          // change the class name and display value
91
          e.className = cl;
92
          e.style.display = "block";
93
          
94
          // mark the comment or cdata display as a expandable container
95
          j = e.parentElement.children(0);
96
          j.className = "c";
97

    
98
          // find the +/- symbol and make it visible - the dummy link enables tabbing
99
          k = j.children(0);
100
          k.style.visibility = "visible";
101
          k.href = "#";
102
        }
103

    
104
        // Change the +/- symbol and hide the children.  This function works on "element"
105
        //  displays
106
        function ch(e)
107
        {
108
          // find the +/- symbol
109
          mark = e.children(0).children(0);
110
          
111
          // if it is already collapsed, expand it by showing the children
112
          if (mark.innerText == "+")
113
          {
114
            mark.innerText = "-";
115
            for (var i = 1; i < e.children.length; i++)
116
              e.children(i).style.display = "block";
117
          }
118
          
119
          // if it is expanded, collapse it by hiding the children
120
          else if (mark.innerText == "-")
121
          {
122
            mark.innerText = "+";
123
            for (var i = 1; i < e.children.length; i++)
124
              e.children(i).style.display="none";
125
          }
126
        }
127
        
128
        // Change the +/- symbol and hide the children.  This function work on "comment"
129
        //  and "cdata" displays
130
        function ch2(e)
131
        {
132
          // find the +/- symbol, and the "PRE" element that contains the content
133
          mark = e.children(0).children(0);
134
          contents = e.children(1);
135
          
136
          // if it is already collapsed, expand it by showing the children
137
          if (mark.innerText == "+")
138
          {
139
            mark.innerText = "-";
140
            // restore the correct "block"/"inline" display type to the PRE
141
            if (contents.className == "db" || contents.className == "cb")
142
              contents.style.display = "block";
143
            else contents.style.display = "inline";
144
          }
145
          
146
          // if it is expanded, collapse it by hiding the children
147
          else if (mark.innerText == "-")
148
          {
149
            mark.innerText = "+";
150
            contents.style.display = "none";
151
          }
152
        }
153
        
154
        // Handle a mouse click
155
        function cl()
156
        {
157
          e = window.event.srcElement;
158
          
159
          // make sure we are handling clicks upon expandable container elements
160
          if (e.className != "c")
161
          {
162
            e = e.parentElement;
163
            if (e.className != "c")
164
            {
165
              return;
166
            }
167
          }
168
          e = e.parentElement;
169
          
170
          // call the correct funtion to change the collapse/expand state and display
171
          if (e.className == "e")
172
            ch(e);
173
          if (e.className == "k")
174
            ch2(e);
175
        }
176

    
177
        // Dummy function for expand/collapse link navigation - trap onclick events instead
178
        function ex() 
179
        {}
180

    
181
        // Erase bogus link info from the status window
182
        function h()
183
        {
184
          window.status=" ";
185
        }
186

    
187
        // Set the onclick handler
188
        document.onclick = cl;
189
        
190
      ]]></xsl:comment></SCRIPT>
191
    </HEAD>
192

    
193
    <BODY class="st"><xsl:apply-templates/></BODY>
194

    
195
  </HTML>
196
</xsl:template>
197

    
198
<!-- Templates for each node type follows.  The output of each template has a similar structure
199
  to enable script to walk the result tree easily for handling user interaction. -->
200
  
201
<!-- Template for the DOCTYPE declaration.  No way to get the DOCTYPE, so we just put in a placeholder -->
202
<!--
203
<xsl:template match="node()[nodeType()=10]">
204
  <DIV class="e"><SPAN>
205
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
206
  <SPAN class="d">&lt;!DOCTYPE <xsl:node-name/><I> (View Source for full doctype...)</I>&gt;</SPAN>
207
  </SPAN></DIV>
208
</xsl:template>
209
-->
210
<!-- Template for pis not handled elsewhere -->
211
<!--
212
<xsl:template match="pi()">
213
  <DIV class="e">
214
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
215
  <SPAN class="m">&lt;?</SPAN><SPAN class="pi"><xsl:node-name/> <xsl:value-of/></SPAN><SPAN class="m">?&gt;</SPAN>
216
  </DIV>
217
</xsl:template>
218

    
219
-->
220
<!-- Template for the XML declaration.  Need a separate template because the pseudo-attributes
221
    are actually exposed as attributes instead of just element content, as in other pis -->
222
<!--
223
<xsl:template match="pi('xml')">
224
  <DIV class="e">
225
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
226
  <SPAN class="m">&lt;?</SPAN><SPAN class="pi">xml <xsl:for-each select="@*"><xsl:node-name/>="<xsl:value-of/>" </xsl:for-each></SPAN><SPAN class="m">?&gt;</SPAN>
227
  </DIV>
228
</xsl:template>
229
-->
230
<!-- Template for attributes not handled elsewhere -->
231
<xsl:template match="@*" xml:space="preserve"><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*/@*">x</xsl:if>t</xsl:attribute> <xsl:node-name/></SPAN><SPAN class="m">="</SPAN><B><xsl:value-of/></B><SPAN class="m">"</SPAN></xsl:template>
232

    
233
<!-- Template for attributes in the xmlns or xml namespace -->
234
<xsl:template match="@xmlns:*|@xmlns|@xml:*"><SPAN class="ns"> <xsl:node-name/></SPAN><SPAN class="m">="</SPAN><B class="ns"><xsl:value-of/></B><SPAN class="m">"</SPAN></xsl:template>
235

    
236
<!-- Template for attributes in the dt namespace -->
237
<xsl:template match="@dt:*|@d2:*"><SPAN class="dt"> <xsl:node-name/></SPAN><SPAN class="m">="</SPAN><B class="dt"><xsl:value-of/></B><SPAN class="m">"</SPAN></xsl:template>
238

    
239
<!-- Template for text nodes -->
240
<xsl:template match="textNode()">
241
  <DIV class="e">
242
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
243
  <SPAN class="tx"><xsl:value-of/></SPAN>
244
  </DIV>
245
</xsl:template>
246

    
247

    
248
<!-- Note that in the following templates for comments and cdata, by default we apply a style
249
  appropriate for single line content (e.g. non-expandable, single line display).  But we also
250
  inject the attribute 'id="clean"' and a script call 'f(clean)'.  As the output is read by the
251
  browser, it executes the function immediately.  The function checks to see if the comment or
252
  cdata has multi-line data, in which case it changes the style to a expandable, multi-line
253
  display.  Performing this switch in the DHTML instead of from script in the XSL increases
254
  the performance of the style sheet, especially in the browser's asynchronous case -->
255
  
256
<!-- Template for comment nodes -->
257
<xsl:template match="comment()">
258
  <DIV class="k">
259
  <SPAN><A class="b" onclick="return false" onfocus="h()" STYLE="visibility:hidden">-</A> <SPAN class="m">&lt;!--</SPAN></SPAN>
260
  <SPAN id="clean" class="ci"><PRE><xsl:value-of/></PRE></SPAN>
261
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">--&gt;</SPAN>
262
  <SCRIPT>f(clean);</SCRIPT></DIV>
263
</xsl:template>
264

    
265
<!-- Template for cdata nodes -->
266
<xsl:template match="cdata()">
267
  <DIV class="k">
268
  <SPAN><A class="b" onclick="return false" onfocus="h()" STYLE="visibility:hidden">-</A> <SPAN class="m">&lt;![CDATA[</SPAN></SPAN>
269
  <SPAN id="clean" class="di"><PRE><xsl:value-of/></PRE></SPAN>
270
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">]]&gt;</SPAN>
271
  <SCRIPT>f(clean);</SCRIPT></DIV>
272
</xsl:template>
273

    
274

    
275
<!-- Note the following templates for elements may examine children.  This harms to some extent
276
  the ability to process a document asynchronously - we can't process an element until we have
277
  read and examined at least some of its children.  Specifically, the first element child must
278
  be read before any template can be chosen.  And any element that does not have element
279
  children must be read completely before the correct template can be chosen. This seems 
280
  an acceptable performance loss in the light of the formatting possibilities available 
281
  when examining children. -->
282

    
283
<!-- Template for elements not handled elsewhere (leaf nodes) -->
284
<xsl:template match="*">
285
  <DIV class="e"><DIV STYLE="margin-left:1em;text-indent:-2em">
286
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN>
287
  <SPAN class="m">&lt;</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN> <xsl:apply-templates select="@*"/><SPAN class="m"> /&gt;</SPAN>
288
  </DIV></DIV>
289
</xsl:template>
290
  
291
<!-- Template for elements with comment, pi and/or cdata children -->
292
<xsl:template match="*[node()]">
293
  <DIV class="e">
294
  <DIV class="c"><A href="#" onclick="return false" onfocus="h()" class="b">-</A> <SPAN class="m">&lt;</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><xsl:apply-templates select="@*"/> <SPAN class="m">&gt;</SPAN></DIV>
295
  <DIV><xsl:apply-templates/>
296
  <DIV><SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">&lt;/</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><SPAN class="m">&gt;</SPAN></DIV>
297
  </DIV></DIV>
298
</xsl:template>
299

    
300
<!-- Template for elements with only text children -->
301
<xsl:template match="*[textNode()$and$$not$(comment()$or$pi()$or$cdata())]">
302
  <DIV class="e"><DIV STYLE="margin-left:1em;text-indent:-2em">
303
  <SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">&lt;</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><xsl:apply-templates select="@*"/>
304
  <SPAN class="m">&gt;</SPAN><SPAN class="tx"><xsl:value-of/></SPAN><SPAN class="m">&lt;/</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><SPAN class="m">&gt;</SPAN>
305
  </DIV></DIV>
306
</xsl:template>
307

    
308
<!-- Template for elements with element children -->
309
<xsl:template match="*[*]">
310
  <DIV class="e">
311
  <DIV class="c" STYLE="margin-left:1em;text-indent:-2em"><A href="#" onclick="return false" onfocus="h()" class="b">-</A> <SPAN class="m">&lt;</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><xsl:apply-templates select="@*"/> <SPAN class="m">&gt;</SPAN></DIV>
312
  <DIV><xsl:apply-templates/>
313
  <DIV><SPAN class="b"><xsl:entity-ref name="nbsp"/></SPAN> <SPAN class="m">&lt;/</SPAN><SPAN><xsl:attribute name="class"><xsl:if match="xsl:*">x</xsl:if>t</xsl:attribute><xsl:node-name/></SPAN><SPAN class="m">&gt;</SPAN></DIV>
314
  </DIV></DIV>
315
</xsl:template>
316

    
317
</xsl:stylesheet>
(8-8/12)