prettyxml.xsl
3.23 KB
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
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--xsl:output method="html" encoding="ISO-8859-1"/-->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- XML formatting -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--
draws an element as xml document
-->
<xsl:template match="/">
<div class="captioneddiv">
<h3>XML presentation</h3>
<br/>
<xsl:apply-templates mode="showXMLElement" select="."/>
</div>
</xsl:template>
<!--
draws an element in xml
-->
<xsl:template mode="showXMLElement" match="*">
<xsl:choose>
<!-- has children -->
<xsl:when test="*">
<xsl:call-template name="showXMLStartTag"/>
<dl>
<xsl:for-each select="*">
<dd>
<xsl:apply-templates select="." mode="showXMLElement"/>
</dd>
</xsl:for-each>
</dl>
<xsl:call-template name="showEndTag"/>
</xsl:when>
<!-- no children but text -->
<xsl:when test="text()">
<xsl:call-template name="showXMLStartTag"/>
<xsl:value-of select="text()"/>
<xsl:call-template name="showEndTag"/>
</xsl:when>
<!-- empty element -->
<xsl:otherwise>
<xsl:call-template name="showXMLStartEndTag"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
draws the start tag of an element
-->
<xsl:template name="showXMLStartTag">
<font color="#4444ff">
<xsl:text><</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:call-template name="showXMLNamespaces"/>
<xsl:call-template name="showXMLAttributes"/>
<xsl:text>></xsl:text>
</font>
</xsl:template>
<!--
draws the end tag of an element
-->
<xsl:template name="showEndTag">
<font color="#4444ff">
<xsl:text></</xsl:text>
<xsl:value-of select="name(.)"/>
<xsl:text>></xsl:text>
</font>
</xsl:template>
<!--
draws the empty tag of an element
-->
<xsl:template name="showXMLStartEndTag">
<font color="#4444ff">
<xsl:text><</xsl:text>
<xsl:value-of select="name(.)"/>
</font>
<xsl:call-template name="showXMLNamespaces"/>
<xsl:call-template name="showXMLAttributes"/>
<font color="#4444ff">
<xsl:text>/></xsl:text>
</font>
</xsl:template>
<!--
draws attributes of an element
-->
<xsl:template name="showXMLAttributes">
<xsl:for-each select="@*">
<xsl:text> </xsl:text>
<font color="#44aa44">
<xsl:value-of select="name(.)"/>
</font>
<xsl:text>=</xsl:text>
<font color="#ff4444">
<xsl:text>"</xsl:text>
<xsl:value-of select="string()"/>
<xsl:text>"</xsl:text>
</font>
</xsl:for-each>
</xsl:template>
<!--
draws namespaces of an element
-->
<xsl:template name="showXMLNamespaces">
<xsl:variable name="parent" select=".."/>
<xsl:for-each select="namespace::*">
<xsl:if test="not(.=$parent/namespace::*) and name()!='geonet'">
<xsl:text> xmlns</xsl:text>
<xsl:if test="name()">
<xsl:text>:</xsl:text>
<xsl:value-of select="name()"/>
</xsl:if>
<xsl:text>=</xsl:text>
<font color="#888844">
<xsl:text>"</xsl:text>
<xsl:value-of select="string()"/>
<xsl:text>"</xsl:text>
</font>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>