forked from Samirla/xmlview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.xsl
141 lines (119 loc) · 5.43 KB
/
browser.xsl
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
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method="html"
version="1.0"
encoding="utf-8"
indent="no"
cdata-section-elements="script"
/>
<xsl:template match="/">
<html lang="en-US">
<head>
<meta charset="UTF-8"/>
<xsl:comment>
<xsl:value-of select="concat(system-property('xsl:version'), '/', system-property('xsl:vendor'), '/', system-property('xsl:vendor-url'))"/>
</xsl:comment>
<style type="text/css">
<![CDATA[ @CSS@ ]]>
</style>
</head>
<body>
<div class="xv-search-panel">
<input type="search" class="xv-search-field" spellcheck="false" placeholder="Search by name or XPath" />
<span class="xv-search-xpath-result"></span>
</div>
<div class="xv-source-pane">
<div class="xv-source-pane-inner"></div>
</div>
<div id="xv-source-data"><xsl:apply-templates/></div>
<script type="text/javascript">
<![CDATA[
@JS@
;xv_controller.process(document.getElementById('xv-source-data').textContent);
]]>
</script>
</body>
</html>
</xsl:template>
<xsl:template match="comment()">
<!-- <xsl:value-of select="." /> -->
</xsl:template>
<xsl:template match="processing-instruction()">
<?<xsl:value-of select="name()"/><xsl:if test="string-length(.) > 0"><xsl:text> </xsl:text><xsl:value-of select="."/></xsl:if>?>
</xsl:template>
<xsl:template match="text()">
<xsl:apply-templates select="." mode="attr-process"/>
</xsl:template>
<!-- elements with mixed content -->
<xsl:template match="*[*|comment()|processing-instruction()]">
<<xsl:value-of select="name()"/><xsl:call-template name='namespaces'/><xsl:apply-templates select="@*"/>>
<xsl:apply-templates/>
</<xsl:value-of select="name()"/>>
</xsl:template>
<!-- elements without mixed content -->
<xsl:template match="*">
<xsl:variable name="lname" select="concat('name_', local-name())" />
<<xsl:value-of select="name()"/><xsl:call-template name='namespaces'/><xsl:apply-templates select="@*"/>><xsl:apply-templates/></<xsl:value-of select="name()"/>>
</xsl:template>
<xsl:template match="@*">
<xsl:text> </xsl:text><xsl:value-of select="name()"/>=<xsl:apply-templates select="." mode="attrvalue"/>
</xsl:template>
<!-- Try to emit well-formed markup for all single/double quote combinations in attribute values -->
<xsl:template match="@*[not(contains(., '"'))]" mode='attrvalue'>"<xsl:apply-templates select="." mode="attr-process"/>"</xsl:template>
<xsl:template match='@*[not(contains(., "'"))]' mode='attrvalue'>'<xsl:apply-templates select="." mode="attr-process"/>'</xsl:template>
<xsl:template match='@*[contains(., "'") and contains(., '"')]' mode='attrvalue'>"<xsl:variable name="attr">
<xsl:apply-templates select="." mode="attr-process"/>
</xsl:variable><xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="$attr"/>
<xsl:with-param name="charsIn" select="'"'"/>
<xsl:with-param name="charsOut" select="'&quot;'"/>
</xsl:call-template>"</xsl:template>
<!-- Default attribute processing: escape &, < and > -->
<xsl:template match="@*|text()" mode="attr-process"><xsl:variable name="p1"><xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="string(.)" />
<xsl:with-param name="charsIn" select="'&'" />
<xsl:with-param name="charsOut" select="'&amp;'" />
</xsl:call-template></xsl:variable>
<xsl:variable name="p2"><xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="$p1" />
<xsl:with-param name="charsIn" select="'<'" />
<xsl:with-param name="charsOut" select="'&lt;'" />
</xsl:call-template></xsl:variable>
<xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="$p2" />
<xsl:with-param name="charsIn" select="'>'" />
<xsl:with-param name="charsOut" select="'&gt;'" />
</xsl:call-template></xsl:template>
<!-- Emit namespace declarations -->
<xsl:template name="namespaces">
<xsl:for-each select="@*|.">
<xsl:variable name="my_ns" select="namespace-uri()"/>
<!-- Emit a namespace declaration if this element or attribute has a namespace and no ancestor already defines it.
Currently this produces redundant declarations for namespaces used only on attributes. -->
<xsl:if test="$my_ns and not(ancestor::*[namespace-uri() = $my_ns])">
<xsl:variable name="prefix" select="substring-before(name(), local-name())"/>
xmlns<xsl:if test="$prefix">:<xsl:value-of select="substring-before($prefix, ':')"/></xsl:if>='<xsl:value-of select="namespace-uri()"/>'
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- string search/replace used in the attribute quote templates above. From http://www.dpawson.co.uk/xsl/sect2/replace.html -->
<xsl:template name="replaceCharsInString">
<xsl:param name="stringIn" />
<xsl:param name="charsIn" />
<xsl:param name="charsOut" />
<xsl:choose>
<xsl:when test="contains($stringIn,$charsIn)">
<xsl:value-of select="concat(substring-before($stringIn,$charsIn),$charsOut)" />
<xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="substring-after($stringIn,$charsIn)" />
<xsl:with-param name="charsIn" select="$charsIn" />
<xsl:with-param name="charsOut" select="$charsOut" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$stringIn" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>