-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.xsl
92 lines (84 loc) · 3.31 KB
/
base.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:local="/"
exclude-result-prefixes="xs local"
version="2.0">
<xsl:template match="/">
<html>
<head>
<style type="text/css">
div {
display:block;
border-left:1px #C0C0C0 solid;
padding-left:1em;
padding-bottom:1rem;
}
span {
display:inline-block;
border:1px #C0C0C0 solid;
padding:1px;
}
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="/*">
<!-- Do not display root node, start with its children -->
<xsl:apply-templates/>
</xsl:template>
<xsl:function name="local:isPara" as="xs:boolean">
<xsl:param name="this" as="element()"/>
<xsl:value-of select="not($this/text()) or $this/text()[string-length(normalize-space()) gt 0]"/>
</xsl:function>
<xsl:function name="local:listAttributes" as="xs:string*">
<xsl:param name="this" as="element()"/>
<xsl:for-each select="$this/@*[not(starts-with(name(.), 'xml:'))]">
<xsl:value-of select="name()"/>
<xsl:text>=</xsl:text>
<xsl:value-of select="data()"/>
<xsl:if test="position() ne last()">
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:function>
<xsl:template match="*[child::* and not(local:isPara(.))]" priority="-50">
<xsl:element name="h{ if(count(ancestor::*) lt 4) then count(ancestor::*) else 4 }">
<xsl:attribute name="title" select="local:listAttributes(.)"/>
<xsl:attribute name="id" select="(@xml:id, generate-id())[1]"/>
<xsl:value-of select="name()"/>
</xsl:element>
<div style="margin-left:1rem;" class="{ local-name() }">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="*" priority="-100">
<div class="{ local-name() }" style="border-left-width:0px;">
<xsl:attribute name="id" select="(@xml:id, generate-id())[1]"/>
<b>
<xsl:attribute name="title" select="local:listAttributes(.)"/>
<xsl:value-of select="name()"/>
<xsl:text>: </xsl:text>
</b>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="*[some $a in ancestor::* satisfies local:isPara($a)]" priority="-1">
<span>
<xsl:attribute name="id" select="(@xml:id, generate-id())[1]"/>
<xsl:attribute name="title">
<xsl:value-of select="name()"/>
<xsl:if test="@*">
<xsl:text> (</xsl:text>
<xsl:value-of select="local:listAttributes(.)"/>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:attribute>
<xsl:apply-templates/>
</span>
</xsl:template>
</xsl:stylesheet>