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
|
<?xml version="1.0" ?>
<!--
This file was obtained from https://github.com/Boldewyn/view-source project:
https://raw.githubusercontent.com/Boldewyn/view-source/f425605366b9f5a52e6a71632785d6e4543c705e/library.xsl
Licensing governed with:
https://github.com/Boldewyn/view-source/blob/f425605366b9f5a52e6a71632785d6e4543c705e/README
> The stylesheet is published under an MIT-style license and the GPL v2.
> Choose at your liking.
-->
<t:stylesheet version="1.0"
xmlns:t="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
<t:variable name="ns" xmlns="">
<empty></empty>
<xml>http://www.w3.org/XML/1998/namespace</xml>
<xmlns>http://www.w3.org/2000/xmlns/</xmlns>
<xhtml>http://www.w3.org/1999/xhtml</xhtml>
<svg>http://www.w3.org/2000/svg</svg>
<mathml>http://www.w3.org/1998/Math/MathML</mathml>
<xslt>http://www.w3.org/1999/XSL/Transform</xslt>
<fo>http://www.w3.org/1999/XSL/Format</fo>
<smil>http://www.w3.org/2005/SMIL21/Language</smil>
<xlink>http://www.w3.org/1999/xlink</xlink>
<xsd>http://www.w3.org/2001/XMLSchema</xsd>
<xsd-inst>http://www.w3.org/2001/XMLSchema-instance</xsd-inst>
<xforms>http://www.w3.org/2001/xforms</xforms>
<xinclude>http://www.w3.org/2001/XInclude</xinclude>
<xul>http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul</xul>
<rdf>http://www.w3.org/1999/02/22-rdf-syntax-ns#</rdf>
</t:variable>
<!--
format text, so that newlines get indented correctly
-->
<t:template name="format-text">
<t:param name="text" select="." />
<t:param name="indent" />
<t:choose>
<t:when test="contains($text, '
')">
<t:value-of select="normalize-space(substring-before($text, '
'))" />
<t:text>
</t:text>
<t:value-of select="$indent" />
<t:call-template name="format-text">
<t:with-param name="text" select="substring-after($text, '
')" />
<t:with-param name="indent" select="$indent " />
</t:call-template>
</t:when>
<t:otherwise>
<t:value-of select="normalize-space($text)" />
</t:otherwise>
</t:choose>
</t:template>
<!--
HTML entity quote stuff
-->
<t:template name="quote">
<t:param name="text" />
<t:call-template name="replace">
<t:with-param name="text">
<t:call-template name="replace">
<t:with-param name="text">
<t:call-template name="replace">
<t:with-param name="text">
<t:call-template name="replace">
<t:with-param name="text">
<t:call-template name="replace">
<t:with-param name="text">
<t:value-of select="$text" />
</t:with-param>
<t:with-param name="from" select="'&'" />
<t:with-param name="to" select="'&amp;'" />
</t:call-template>
</t:with-param>
<t:with-param name="from" select='"'"' />
<t:with-param name="to" select="'&apos;'" />
</t:call-template>
</t:with-param>
<t:with-param name="from" select="'"'" />
<t:with-param name="to" select="'&quot;'" />
</t:call-template>
</t:with-param>
<t:with-param name="from" select="'>'" />
<t:with-param name="to" select="'&gt;'" />
</t:call-template>
</t:with-param>
<t:with-param name="from" select="'<'" />
<t:with-param name="to" select="'&lt;'" />
</t:call-template>
</t:template>
<!--
replace a string with another
-->
<t:template name="replace">
<t:param name="text" />
<t:param name="from" />
<t:param name="to" />
<t:choose>
<t:when test="not($from)">
<t:value-of select="$text" />
</t:when>
<t:when test="contains($text, $from)">
<t:value-of select="substring-before($text, $from)" />
<t:value-of select="$to" />
<t:call-template name="replace">
<t:with-param name="text" select="substring-after($text, $from)" />
<t:with-param name="from" select="$from" />
<t:with-param name="to" select="$to" />
</t:call-template>
</t:when>
<t:otherwise>
<t:value-of select="$text" />
</t:otherwise>
</t:choose>
</t:template>
<!--
parse the value of an attribute (find links and make them clickable)
-->
<t:template name="parse-attval">
<t:param name="att" select="." />
<t:choose>
<!-- FIXME: element{xhtml} / @attr{obscure-ns} 'href' gets linkified -->
<t:when test="(namespace-uri($att/..) = document('')//t:variable[@name = 'ns']/xml/text() and ( local-name($att) = 'base' )) or
(namespace-uri($att/..) = document('')//t:variable[@name = 'ns']/xhtml/text() and ( local-name($att) = 'src' or local-name($att) = 'href' )) or
(namespace-uri($att/..) = document('')//t:variable[@name = 'ns']/svg/text() and ( local-name($att) = 'src' )) or
(namespace-uri($att/..) = document('')//t:variable[@name = 'ns']/xslt/text() and ( local-name($att) = 'href' )) or
(namespace-uri($att/..) = document('')//t:variable[@name = 'ns']/smil/text() and ( local-name($att) = 'src' or local-name($att) = 'href' )) or
(namespace-uri($att) = document('')//t:variable[@name = 'ns']/xlink/text() and ( local-name($att) = 'href' or local-name($att) = 'role' )) or
contains(substring($att, 1, 7), 'http://') or
contains(substring($att, 1, 8), 'https://') or
contains(substring($att, 1, 7), 'file://') or
contains(substring($att, 1, 7), 'mailto:') or
contains(substring($att, 1, 6), 'ftp://') or
contains(substring($att, 1, 7), 'ftps://') or
contains(substring($att, 1, 5), 'news:') or
contains(substring($att, 1, 4), 'urn:') or
contains(substring($att, 1, 5), 'ldap:') or
contains(substring($att, 1, 5), 'data:')">
<a>
<t:attribute name="href">
<t:value-of select="$att" />
</t:attribute>
<t:call-template name="quote">
<t:with-param name="text" select="$att" />
</t:call-template>
</a>
</t:when>
<t:otherwise>
<t:call-template name="quote">
<t:with-param name="text" select="$att" />
</t:call-template>
</t:otherwise>
</t:choose>
</t:template>
<!--
print the name of a node plus the namespace URI in a title attribute
-->
<t:template name="print-name">
<t:param name="node" select="." />
<span class="label">
<t:if test="namespace-uri($node)">
<t:attribute name="title">
<t:value-of select="namespace-uri($node)" />
</t:attribute>
</t:if>
<t:choose>
<t:when test="name($node) != local-name($node)">
<span class="nsprefix">
<t:value-of select="substring-before(name($node), ':')" />
</span>
<span class="nscolon syntax">
<t:text>:</t:text>
</span>
<span class="local-name">
<t:value-of select="local-name($node)" />
</span>
</t:when>
<t:otherwise>
<t:value-of select="name($node)" />
</t:otherwise>
</t:choose>
</span>
</t:template>
<!--
check the used language against a list of known ones
-->
<t:template name="detect-lang">
<t:param name="node" select="." />
<t:if test="namespace-uri($node) = $highlight-namespace">
<t:text>highlight </t:text>
</t:if>
<t:value-of select="local-name(document('')//t:variable[@name = 'ns']/*[text() = namespace-uri($node)])" />
</t:template>
<t:key name="kElemByNSURI"
match="*[namespace::*[not(. = ../../namespace::*)]]"
use="namespace::*[not(. = ../../namespace::*)]" />
<!--
get a list of all namespaces used in the document
-->
<t:template name="get-namespace-nodes">
<script type="text/javascript">
var namespaces = [
<t:for-each select="//namespace::*[not(. = ../../namespace::*)]
[count(..|key('kElemByNSURI',.)[1])=1]">
<t:value-of select="concat('"',.,'",')"/>
</t:for-each>
'DUMMY'
];
</script>
</t:template>
</t:stylesheet>
|