-
Notifications
You must be signed in to change notification settings - Fork 0
/
fill.xsl
111 lines (67 loc) · 2.85 KB
/
fill.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
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.0">
<xsl:output method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:param name="style" select="'style'"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:svg">
<xsl:text disable-output-escaping="yes"><!--</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text disable-output-escaping="yes">--></xsl:text>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
<xsl:if test="$style='pattern-fill'">
<xsl:apply-templates select="document('./pattern-defs.xml')"/>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:polygons">
<xsl:text disable-output-escaping="yes"><!--</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text disable-output-escaping="yes">--></xsl:text>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="svg:style">
<xsl:text disable-output-escaping="yes"><!--</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text disable-output-escaping="yes">--></xsl:text>
<style>
<xsl:value-of select="document('./style.xml')"/>
</style>
</xsl:template>
<xsl:template match="svg:path">
<!-- NOTE: the value of position() is a function of the chidren of the parent "<g>" node, including it's attributes. This means
if there is a "class" attribute on the "<g>" node we will have to account for it on the counter if we are trying to
accuratley count the number of child path elements starting at 1 -->
<xsl:variable name="i" select="position() - 1" />
<xsl:text disable-output-escaping="yes"><!--</xsl:text> position is <xsl:value-of select="position()"/> and $i is <xsl:value-of select="$i"/> <xsl:text disable-output-escaping="yes">--></xsl:text>
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
<xsl:choose>
<xsl:when test="$style='pattern-fill'">
<xsl:attribute name="class"> <xsl:value-of select="concat('fill', $i mod 48)"/></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="document('/tmp/groups.xml')/color-groups/group">
<xsl:variable name="group_count" select="position()"/>
<xsl:choose>
<xsl:when test="$i = $group_count">
<xsl:attribute name="class">group<xsl:value-of select="current()"/></xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="id"> <xsl:value-of select="concat('mypath', $i)"/></xsl:attribute>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>