-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodgraph.xsl
70 lines (59 loc) · 2.58 KB
/
modgraph.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
<?xml version="1.1"?>
<!--
ATLauncher Configs.xml grapher
Author: Léa Gris @ Beyond Reality Team https://github.com/Beyond-Reality
Date: 2017-05-29
Version: 1.0.0
License: http://www.wtfpl.net/
Example usage:
xsltproc modgraph.xsl Configs.xml > graph.svg
saxon-xslt Configs.xml modgraph.xsl > graph.svg
-->
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2000/svg"
>
<xsl:output
method="xml"
indent="yes"
standalone="no"
doctype-public="-//W3C//DTD SVG 1.1//EN"
doctype-system="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
media-type="image/svg"/>
<xsl:key name="mods-by-colour" match="/version/mods/mod" use="@colour"/>
<xsl:template match="*">
<xsl:apply-templates select="mods"/>
</xsl:template>
<xsl:template match="mods">
<xsl:variable name="maxwidth">
<xsl:value-of select="20 + 216 * count(mod[count(. | key('mods-by-colour', @colour)[1]) = 1])"/>
</xsl:variable>
<xsl:variable name="maxheight">
<xsl:for-each select="mod[count(. | key('mods-by-colour', @colour)[1]) = 1]">
<xsl:sort select="count(key('mods-by-colour', @colour))" data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="42 + 24 * count(key('mods-by-colour', @colour))"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<svg xmlns="http://www.w3.org/2000/svg" width="{$maxwidth}" height="{$maxheight}">
<xsl:for-each select="mod[count(. | key('mods-by-colour', @colour)[1]) = 1]">
<xsl:sort select="@colour"/>
<xsl:variable name="colourname" select="@colour"/>
<xsl:variable name="dx" select="position() - 1"/>
<xsl:variable name="colourcode" select="/version/colours/colour[@name=$colourname]/@code"/>
<g name="{$colourname}" transform="translate({10+ $dx * 216}, 10)">
<text x="104" y="16" font-size="16px" font-weight="bold" dominant-baseline="central" text-anchor="middle"><xsl:value-of select="@colour"/></text>
<xsl:for-each select="key('mods-by-colour', @colour)">
<xsl:sort select="@name"/>
<xsl:variable name="dy" select="position() - 1"/>
<g transform="translate(0,{32 + $dy * 24})">
<rect x="0" y="0" width="208" height="16" fill="{$colourcode}" stroke="black"/>
<text x="104" y="8" font-size="12px" dominant-baseline="central" text-anchor="middle"><xsl:value-of select="@name"/></text>
</g>
</xsl:for-each>
</g>
</xsl:for-each>
</svg>
</xsl:template>
</xsl:stylesheet>