forked from Roenbaeck/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml2html.xsl
95 lines (95 loc) · 3.4 KB
/
xml2html.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
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="no"/>
<xsl:template match="node()">
<xsl:param name="indent" select="''"/>
<span class="tabs">
<xsl:value-of select="$indent"/>
</span>
<span class="brackets">
<xsl:text><</xsl:text>
</span>
<span class="elements">
<xsl:value-of select="local-name(.)"/>
</span>
<xsl:for-each select="@*">
<xsl:text> </xsl:text>
<span class="attributes">
<xsl:value-of select="local-name(.)"/>
</span>
<span class="brackets">
<xsl:text>="</xsl:text>
</span>
<span class="values">
<xsl:value-of select="."/>
</span>
<span class="brackets">
<xsl:text>"</xsl:text>
</span>
</xsl:for-each>
<xsl:if test=".. and not(parent::*) and namespace-uri()">
<xsl:text> </xsl:text>
<span class="attributes">
<xsl:text>xmlns</xsl:text>
</span>
<span class="brackets">
<xsl:text>="</xsl:text>
</span>
<span class="values">
<xsl:value-of select="namespace-uri()"/>
</span>
<span class="brackets">
<xsl:text>"</xsl:text>
</span>
</xsl:if>
<xsl:choose>
<xsl:when test="normalize-space(text())">
<span class="brackets">
<xsl:text>></xsl:text><br/>
</span>
<span class="tabs">
<xsl:value-of select="concat($indent, 'TAB')"/>
</span>
<span class="texts">
<xsl:value-of select="text()"/><br/>
</span>
<span class="tabs">
<xsl:value-of select="$indent"/>
</span>
<span class="brackets">
<xsl:text></</xsl:text>
</span>
<span class="elements">
<xsl:value-of select="local-name(.)"/>
</span>
<span class="brackets">
<xsl:text>></xsl:text><br/>
</span>
</xsl:when>
<xsl:when test="node()">
<span class="brackets">
<xsl:text>></xsl:text><br/>
</span>
<xsl:apply-templates select="node()">
<xsl:with-param name="indent" select="concat($indent, 'TAB')"/>
</xsl:apply-templates>
<span class="tabs">
<xsl:value-of select="$indent"/>
</span>
<span class="brackets">
<xsl:text></</xsl:text>
</span>
<span class="elements">
<xsl:value-of select="local-name(.)"/>
</span>
<span class="brackets">
<xsl:text>></xsl:text><br/>
</span>
</xsl:when>
<xsl:otherwise>
<span class="brackets">
<xsl:text>/></xsl:text><br/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>