content/xml/document/resources/XMLPrettyPrint.xsl

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1fe0c946fb34
1 <?xml version="1.0"?>
2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
3 - License, v. 2.0. If a copy of the MPL was not distributed with this
4 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
5
6 <!DOCTYPE overlay [
7 <!ENTITY % prettyPrintDTD SYSTEM "chrome://global/locale/xml/prettyprint.dtd">
8 %prettyPrintDTD;
9 <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
10 %globalDTD;
11 ]>
12
13 <xsl:stylesheet version="1.0"
14 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
15 xmlns="http://www.w3.org/1999/xhtml">
16
17 <xsl:output method="xml"/>
18
19 <xsl:template match="/">
20 <link href="chrome://global/content/xml/XMLPrettyPrint.css" type="text/css" rel="stylesheet"/>
21 <link title="Monospace" href="chrome://global/content/xml/XMLMonoPrint.css" type="text/css" rel="alternate stylesheet"/>
22 <div id="header" dir="&locale.dir;">
23 <p>
24 &xml.nostylesheet;
25 </p>
26 </div>
27 <xsl:apply-templates/>
28 </xsl:template>
29
30 <xsl:template match="*">
31 <div>
32 <xsl:text>&lt;</xsl:text>
33 <span class="start-tag"><xsl:value-of select="name(.)"/></span>
34 <xsl:apply-templates select="@*"/>
35 <xsl:text>/&gt;</xsl:text>
36 </div>
37 </xsl:template>
38
39 <xsl:template match="*[node()]">
40 <div>
41 <xsl:text>&lt;</xsl:text>
42 <span class="start-tag"><xsl:value-of select="name(.)"/></span>
43 <xsl:apply-templates select="@*"/>
44 <xsl:text>&gt;</xsl:text>
45
46 <span class="text"><xsl:value-of select="."/></span>
47
48 <xsl:text>&lt;/</xsl:text>
49 <span class="end-tag"><xsl:value-of select="name(.)"/></span>
50 <xsl:text>&gt;</xsl:text>
51 </div>
52 </xsl:template>
53
54 <xsl:template match="*[* or processing-instruction() or comment() or string-length(.) &gt; 50]">
55 <div class="expander-open">
56 <xsl:call-template name="expander"/>
57
58 <xsl:text>&lt;</xsl:text>
59 <span class="start-tag"><xsl:value-of select="name(.)"/></span>
60 <xsl:apply-templates select="@*"/>
61 <xsl:text>&gt;</xsl:text>
62
63 <div class="expander-content"><xsl:apply-templates/></div>
64
65 <xsl:text>&lt;/</xsl:text>
66 <span class="end-tag"><xsl:value-of select="name(.)"/></span>
67 <xsl:text>&gt;</xsl:text>
68 </div>
69 </xsl:template>
70
71 <xsl:template match="@*">
72 <xsl:text> </xsl:text>
73 <span class="attribute-name"><xsl:value-of select="name(.)"/></span>
74 <xsl:text>=</xsl:text>
75 <span class="attribute-value">"<xsl:value-of select="."/>"</span>
76 </xsl:template>
77
78 <xsl:template match="text()">
79 <xsl:if test="normalize-space(.)">
80 <xsl:value-of select="."/>
81 </xsl:if>
82 </xsl:template>
83
84 <xsl:template match="processing-instruction()">
85 <div class="pi">
86 <xsl:text>&lt;?</xsl:text>
87 <xsl:value-of select="name(.)"/>
88 <xsl:text> </xsl:text>
89 <xsl:value-of select="."/>
90 <xsl:text>?&gt;</xsl:text>
91 </div>
92 </xsl:template>
93
94 <xsl:template match="processing-instruction()[string-length(.) &gt; 50]">
95 <div class="expander-open">
96 <xsl:call-template name="expander"/>
97
98 <span class="pi">
99 <xsl:text> &lt;?</xsl:text>
100 <xsl:value-of select="name(.)"/>
101 </span>
102 <div class="expander-content pi"><xsl:value-of select="."/></div>
103 <span class="pi">
104 <xsl:text>?&gt;</xsl:text>
105 </span>
106 </div>
107 </xsl:template>
108
109 <xsl:template match="comment()">
110 <div class="comment">
111 <xsl:text>&lt;!--</xsl:text>
112 <xsl:value-of select="."/>
113 <xsl:text>--&gt;</xsl:text>
114 </div>
115 </xsl:template>
116
117 <xsl:template match="comment()[string-length(.) &gt; 50]">
118 <div class="expander-open">
119 <xsl:call-template name="expander"/>
120
121 <span class="comment">
122 <xsl:text>&lt;!--</xsl:text>
123 </span>
124 <div class="expander-content comment">
125 <xsl:value-of select="."/>
126 </div>
127 <span class="comment">
128 <xsl:text>--&gt;</xsl:text>
129 </span>
130 </div>
131 </xsl:template>
132
133 <xsl:template name="expander">
134 <div class="expander">&#x2212;</div>
135 </xsl:template>
136
137 </xsl:stylesheet>

mercurial