paul@19 | 1 | <?xml version="1.0" ?> |
paul@19 | 2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" |
paul@19 | 3 | xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"> |
paul@19 | 4 | <xsl:output method="xml" indent="yes" |
paul@19 | 5 | doctype-public="-//W3C//DTD SVG 1.0//EN" |
paul@19 | 6 | doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"/> |
paul@19 | 7 | |
paul@19 | 8 | <xsl:variable name="text-style">font-size:10px; font-family:sans-serif;</xsl:variable> |
paul@19 | 9 | |
paul@19 | 10 | <!-- Used to generate unique gradient fills for colors given by hex value |
paul@19 | 11 | Search for generate-id to find where its used |
paul@19 | 12 | --> |
paul@19 | 13 | <xsl:key name="fills" match="*" use="@fill"/> |
paul@19 | 14 | |
paul@19 | 15 | <xsl:template match="@*|node()"> |
paul@19 | 16 | <xsl:copy> |
paul@19 | 17 | <xsl:apply-templates select="@*|node()"/> |
paul@19 | 18 | </xsl:copy> |
paul@19 | 19 | </xsl:template> |
paul@19 | 20 | |
paul@19 | 21 | <xsl:template match="svg:svg"> |
paul@19 | 22 | <svg xmlns="http://www.w3.org/2000/svg"> |
paul@19 | 23 | <!-- Order is important here, so the attributes below overrides the |
paul@19 | 24 | originals, which are copied "wholesale" --> |
paul@19 | 25 | <xsl:apply-templates select="@*" /> |
paul@19 | 26 | |
paul@19 | 27 | <defs> |
paul@19 | 28 | <linearGradient id="white" x1="0%" y1="0%" x2="0%" y2="0%"> |
paul@19 | 29 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 30 | </linearGradient> |
paul@19 | 31 | |
paul@19 | 32 | <linearGradient id="black" x1="0%" y1="0%" x2="0%" y2="0%"> |
paul@19 | 33 | <stop offset="0%" style="stop-color:rgb(0,0,0);stop-opacity:1"/> |
paul@19 | 34 | </linearGradient> |
paul@19 | 35 | |
paul@19 | 36 | <linearGradient id="aquamarine" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 37 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 38 | <stop offset="100%" style="stop-color:rgb(127,255,212);stop-opacity:1"/> |
paul@19 | 39 | </linearGradient> |
paul@19 | 40 | |
paul@19 | 41 | <linearGradient id="azure" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 42 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 43 | <stop offset="100%" style="stop-color:rgb(240,255,255);stop-opacity:1"/> |
paul@19 | 44 | </linearGradient> |
paul@19 | 45 | |
paul@19 | 46 | <linearGradient id="blue" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 47 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 48 | <stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1"/> |
paul@19 | 49 | </linearGradient> |
paul@19 | 50 | |
paul@19 | 51 | <linearGradient id="blueviolet" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 52 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 53 | <stop offset="100%" style="stop-color:rgb(138,43,226);stop-opacity:1"/> |
paul@19 | 54 | </linearGradient> |
paul@19 | 55 | |
paul@19 | 56 | <linearGradient id="brown" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 57 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 58 | <stop offset="100%" style="stop-color:rgb(165,42,42);stop-opacity:1"/> |
paul@19 | 59 | </linearGradient> |
paul@19 | 60 | |
paul@19 | 61 | <linearGradient id="cadetblue" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 62 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 63 | <stop offset="100%" style="stop-color:rgb(95,158,160);stop-opacity:1"/> |
paul@19 | 64 | </linearGradient> |
paul@19 | 65 | |
paul@19 | 66 | <linearGradient id="chocolate" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 67 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 68 | <stop offset="100%" style="stop-color:rgb(210,105,30);stop-opacity:1"/> |
paul@19 | 69 | </linearGradient> |
paul@19 | 70 | |
paul@19 | 71 | <linearGradient id="cornflowerblue" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 72 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 73 | <stop offset="100%" style="stop-color:rgb(100,149,237);stop-opacity:1"/> |
paul@19 | 74 | </linearGradient> |
paul@19 | 75 | |
paul@19 | 76 | <linearGradient id="crimson" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 77 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 78 | <stop offset="100%" style="stop-color:rgb(220,20,60);stop-opacity:1"/> |
paul@19 | 79 | </linearGradient> |
paul@19 | 80 | |
paul@19 | 81 | <linearGradient id="cyan" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 82 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 83 | <stop offset="100%" style="stop-color:rgb(0,255,255);stop-opacity:1"/> |
paul@19 | 84 | </linearGradient> |
paul@19 | 85 | |
paul@19 | 86 | <linearGradient id="darkgreen" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 87 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 88 | <stop offset="100%" style="stop-color:rgb(0,100,0);stop-opacity:1"/> |
paul@19 | 89 | </linearGradient> |
paul@19 | 90 | |
paul@19 | 91 | <linearGradient id="darkorange" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 92 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 93 | <stop offset="100%" style="stop-color:rgb(255,140,0);stop-opacity:1"/> |
paul@19 | 94 | </linearGradient> |
paul@19 | 95 | |
paul@19 | 96 | <linearGradient id="gold" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 97 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 98 | <stop offset="100%" style="stop-color:rgb(255,215,0);stop-opacity:1"/> |
paul@19 | 99 | </linearGradient> |
paul@19 | 100 | |
paul@19 | 101 | <linearGradient id="gray" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 102 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 103 | <stop offset="100%" style="stop-color:rgb(192,192,192);stop-opacity:1"/> |
paul@19 | 104 | </linearGradient> |
paul@19 | 105 | |
paul@19 | 106 | <linearGradient id="greenyellow" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 107 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 108 | <stop offset="100%" style="stop-color:rgb(173,255,47);stop-opacity:1"/> |
paul@19 | 109 | </linearGradient> |
paul@19 | 110 | |
paul@19 | 111 | <linearGradient id="green" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 112 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 113 | <stop offset="100%" style="stop-color:rgb(0,255,0);stop-opacity:1"/> |
paul@19 | 114 | </linearGradient> |
paul@19 | 115 | |
paul@19 | 116 | <linearGradient id="grey" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 117 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 118 | <stop offset="100%" style="stop-color:rgb(192,192,192);stop-opacity:1"/> |
paul@19 | 119 | </linearGradient> |
paul@19 | 120 | |
paul@19 | 121 | <linearGradient id="hotpink" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 122 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 123 | <stop offset="100%" style="stop-color:rgb(255,105,180);stop-opacity:1"/> |
paul@19 | 124 | </linearGradient> |
paul@19 | 125 | |
paul@19 | 126 | <linearGradient id="indianred" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 127 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 128 | <stop offset="100%" style="stop-color:rgb(205,92,92);stop-opacity:1"/> |
paul@19 | 129 | </linearGradient> |
paul@19 | 130 | |
paul@19 | 131 | <linearGradient id="indigo" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 132 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 133 | <stop offset="100%" style="stop-color:rgb(75,0,130);stop-opacity:1"/> |
paul@19 | 134 | </linearGradient> |
paul@19 | 135 | |
paul@19 | 136 | <linearGradient id="lavender" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 137 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 138 | <stop offset="100%" style="stop-color:rgb(230,230,250);stop-opacity:1"/> |
paul@19 | 139 | </linearGradient> |
paul@19 | 140 | |
paul@19 | 141 | <linearGradient id="lightblue" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 142 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 143 | <stop offset="100%" style="stop-color:rgb(173,216,230);stop-opacity:1"/> |
paul@19 | 144 | </linearGradient> |
paul@19 | 145 | |
paul@19 | 146 | <linearGradient id="lightgray" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 147 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 148 | <stop offset="100%" style="stop-color:rgb(211,211,211);stop-opacity:1"/> |
paul@19 | 149 | </linearGradient> |
paul@19 | 150 | |
paul@19 | 151 | <linearGradient id="lightgrey" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 152 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 153 | <stop offset="100%" style="stop-color:rgb(211,211,211);stop-opacity:1"/> |
paul@19 | 154 | </linearGradient> |
paul@19 | 155 | |
paul@19 | 156 | <linearGradient id="magenta" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 157 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 158 | <stop offset="100%" style="stop-color:rgb(255,0,255);stop-opacity:1"/> |
paul@19 | 159 | </linearGradient> |
paul@19 | 160 | |
paul@19 | 161 | <linearGradient id="maroon" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 162 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 163 | <stop offset="100%" style="stop-color:rgb(176,48,96);stop-opacity:1"/> |
paul@19 | 164 | </linearGradient> |
paul@19 | 165 | |
paul@19 | 166 | <linearGradient id="mediumblue" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 167 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 168 | <stop offset="100%" style="stop-color:rgb(0,0,205);stop-opacity:1"/> |
paul@19 | 169 | </linearGradient> |
paul@19 | 170 | |
paul@19 | 171 | <linearGradient id="mediumpurple" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 172 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 173 | <stop offset="100%" style="stop-color:rgb(147,112,219);stop-opacity:1"/> |
paul@19 | 174 | </linearGradient> |
paul@19 | 175 | |
paul@19 | 176 | <linearGradient id="orange" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 177 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 178 | <stop offset="100%" style="stop-color:rgb(255,165,0);stop-opacity:1"/> |
paul@19 | 179 | </linearGradient> |
paul@19 | 180 | |
paul@19 | 181 | <linearGradient id="pink" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 182 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 183 | <stop offset="100%" style="stop-color:rgb(255,192,203);stop-opacity:1"/> |
paul@19 | 184 | </linearGradient> |
paul@19 | 185 | |
paul@19 | 186 | <linearGradient id="purple" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 187 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 188 | <stop offset="100%" style="stop-color:rgb(160,32,240);stop-opacity:1"/> |
paul@19 | 189 | </linearGradient> |
paul@19 | 190 | |
paul@19 | 191 | <linearGradient id="red" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 192 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 193 | <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1"/> |
paul@19 | 194 | </linearGradient> |
paul@19 | 195 | |
paul@19 | 196 | <linearGradient id="steelblue" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 197 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 198 | <stop offset="100%" style="stop-color:rgb(70,130,180);stop-opacity:1"/> |
paul@19 | 199 | </linearGradient> |
paul@19 | 200 | |
paul@19 | 201 | <linearGradient id="violet" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 202 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 203 | <stop offset="100%" style="stop-color:rgb(238,130,238);stop-opacity:1"/> |
paul@19 | 204 | </linearGradient> |
paul@19 | 205 | |
paul@19 | 206 | <linearGradient id="yellow" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 207 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 208 | <stop offset="100%" style="stop-color:rgb(255,255,0);stop-opacity:1"/> |
paul@19 | 209 | </linearGradient> |
paul@19 | 210 | |
paul@19 | 211 | <linearGradient id="none" x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 212 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 213 | <stop offset="100%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 214 | </linearGradient> |
paul@19 | 215 | |
paul@19 | 216 | <xsl:for-each select="*//*[generate-id() = generate-id(key('fills',@fill)[1])][substring(@fill,1,1)='#']"> |
paul@19 | 217 | <linearGradient x1="0%" y1="0%" x2="100%" y2="100%"> |
paul@19 | 218 | <xsl:attribute name="id">fill-<xsl:value-of select="substring(@fill,2,6)"/></xsl:attribute> |
paul@19 | 219 | <stop offset="0%" style="stop-color:rgb(255,255,255);stop-opacity:1"/> |
paul@19 | 220 | <stop offset="100%"> |
paul@19 | 221 | <xsl:attribute name="style">stop-color:<xsl:value-of select="@fill" />;stop-opacity:1</xsl:attribute> |
paul@19 | 222 | </stop> |
paul@19 | 223 | </linearGradient> |
paul@19 | 224 | </xsl:for-each> |
paul@19 | 225 | |
paul@19 | 226 | </defs> |
paul@19 | 227 | |
paul@19 | 228 | |
paul@19 | 229 | <xsl:apply-templates /> |
paul@19 | 230 | </svg> |
paul@19 | 231 | </xsl:template> |
paul@19 | 232 | |
paul@19 | 233 | <!-- Match the top most "g" --> |
paul@19 | 234 | <xsl:template match="/svg:svg/svg:g"> |
paul@19 | 235 | <g> |
paul@19 | 236 | <xsl:apply-templates select="@*"/> |
paul@19 | 237 | <!-- Graphviz uses a polygon as the background. Don't want a gradient there --> |
paul@19 | 238 | <xsl:for-each select="svg:polygon"> |
paul@19 | 239 | <xsl:copy><xsl:apply-templates select="@*" /></xsl:copy> |
paul@19 | 240 | </xsl:for-each> |
paul@19 | 241 | <xsl:apply-templates select="svg:title|svg:g" /> |
paul@19 | 242 | </g> |
paul@19 | 243 | </xsl:template> |
paul@19 | 244 | |
paul@19 | 245 | |
paul@19 | 246 | <xsl:template match="svg:text"> |
paul@19 | 247 | <text> |
paul@19 | 248 | <xsl:apply-templates select="@*" /> |
paul@19 | 249 | <xsl:if test="not(@font-family) and not(@font-size)"> |
paul@19 | 250 | <xsl:attribute name="style"><xsl:value-of select="$text-style" /></xsl:attribute> |
paul@19 | 251 | </xsl:if> |
paul@19 | 252 | <xsl:apply-templates select="text()"/> |
paul@19 | 253 | </text> |
paul@19 | 254 | </xsl:template> |
paul@19 | 255 | |
paul@19 | 256 | |
paul@19 | 257 | <xsl:template match="svg:g"> |
paul@19 | 258 | <xsl:copy> |
paul@19 | 259 | <xsl:apply-templates select="@*" /> |
paul@19 | 260 | <xsl:choose> |
paul@19 | 261 | <!-- Handle linked groups. --> |
paul@19 | 262 | <xsl:when test="svg:a"> |
paul@19 | 263 | <xsl:for-each select="svg:a"> |
paul@19 | 264 | <xsl:copy> |
paul@19 | 265 | <xsl:apply-templates select="@*" /> |
paul@19 | 266 | <xsl:call-template name="group"> |
paul@19 | 267 | <xsl:with-param name="class" select="../@class"/> |
paul@19 | 268 | </xsl:call-template> |
paul@19 | 269 | </xsl:copy> |
paul@19 | 270 | </xsl:for-each> |
paul@21 | 271 | <!-- Handle labels. --> |
paul@21 | 272 | <xsl:apply-templates select="svg:text" /> |
paul@19 | 273 | </xsl:when> |
paul@19 | 274 | <!-- Handle bare groups. --> |
paul@19 | 275 | <xsl:otherwise> |
paul@19 | 276 | <xsl:call-template name="group"/> |
paul@19 | 277 | </xsl:otherwise> |
paul@19 | 278 | </xsl:choose> |
paul@19 | 279 | </xsl:copy> |
paul@19 | 280 | </xsl:template> |
paul@19 | 281 | |
paul@19 | 282 | |
paul@19 | 283 | <xsl:template name="group"> |
paul@19 | 284 | <xsl:param name="class" select="@class"/> |
paul@19 | 285 | |
paul@19 | 286 | <xsl:for-each select="svg:polygon|svg:ellipse"> |
paul@19 | 287 | <xsl:call-template name="poly-shadow" /> |
paul@19 | 288 | </xsl:for-each> |
paul@19 | 289 | |
paul@19 | 290 | <xsl:choose> |
paul@19 | 291 | <!-- Rewrite node outlines. --> |
paul@19 | 292 | <xsl:when test="$class='node' and svg:path|svg:polyline"> |
paul@19 | 293 | <xsl:call-template name="node-outline"> |
paul@19 | 294 | <xsl:with-param name="current" select="*[1]"/> |
paul@19 | 295 | <xsl:with-param name="style">shadow</xsl:with-param> |
paul@19 | 296 | </xsl:call-template> |
paul@19 | 297 | </xsl:when> |
paul@19 | 298 | <xsl:otherwise> |
paul@19 | 299 | <xsl:for-each select="svg:path"> |
paul@19 | 300 | <xsl:call-template name="path-shadow-edge" /> |
paul@19 | 301 | </xsl:for-each> |
paul@19 | 302 | </xsl:otherwise> |
paul@19 | 303 | </xsl:choose> |
paul@19 | 304 | |
paul@19 | 305 | <xsl:for-each select="svg:polygon|svg:ellipse"> |
paul@19 | 306 | <xsl:sort select="@ry" order="descending" /> |
paul@19 | 307 | <xsl:call-template name="poly-main" /> |
paul@19 | 308 | </xsl:for-each> |
paul@19 | 309 | |
paul@19 | 310 | <xsl:choose> |
paul@19 | 311 | <!-- Rewrite node outlines. --> |
paul@21 | 312 | <xsl:when test="$class='node' and svg:path|svg:polyline"> |
paul@21 | 313 | <xsl:call-template name="node-outline"> |
paul@21 | 314 | <xsl:with-param name="current" select="*[1]"/> |
paul@21 | 315 | </xsl:call-template> |
paul@19 | 316 | </xsl:when> |
paul@19 | 317 | <xsl:otherwise> |
paul@19 | 318 | <xsl:for-each select="svg:path"> |
paul@19 | 319 | <path><xsl:apply-templates select="@*" /></path> |
paul@19 | 320 | </xsl:for-each> |
paul@19 | 321 | </xsl:otherwise> |
paul@19 | 322 | </xsl:choose> |
paul@19 | 323 | |
paul@21 | 324 | <!-- Handle labels. --> |
paul@19 | 325 | <xsl:apply-templates select="svg:text" /> |
paul@19 | 326 | </xsl:template> |
paul@19 | 327 | |
paul@19 | 328 | <xsl:template name="node-outline"> |
paul@19 | 329 | <xsl:param name="path-so-far"/> |
paul@19 | 330 | <xsl:param name="current"/> |
paul@19 | 331 | <xsl:param name="style"/> |
paul@19 | 332 | |
paul@19 | 333 | <xsl:choose> |
paul@19 | 334 | <!-- Visit each child element, collecting the path details. --> |
paul@19 | 335 | <xsl:when test="$current"> |
paul@19 | 336 | <xsl:choose> |
paul@19 | 337 | <xsl:when test="local-name($current) = 'path'"> |
paul@19 | 338 | <xsl:call-template name="filter-path"> |
paul@19 | 339 | <xsl:with-param name="path-so-far" select="$path-so-far"/> |
paul@19 | 340 | <xsl:with-param name="point" select="substring-before($current/@d, 'C')"/> |
paul@19 | 341 | <xsl:with-param name="points" select="concat('C', substring-after($current/@d, 'C'))"/> |
paul@19 | 342 | <xsl:with-param name="current" select="$current"/> |
paul@19 | 343 | <xsl:with-param name="style" select="$style"/> |
paul@19 | 344 | </xsl:call-template> |
paul@19 | 345 | </xsl:when> |
paul@19 | 346 | <xsl:when test="local-name($current) = 'polyline'"> |
paul@19 | 347 | <xsl:call-template name="polyline-to-path"> |
paul@19 | 348 | <xsl:with-param name="path-so-far" select="$path-so-far"/> |
paul@19 | 349 | <xsl:with-param name="point" select="concat('M', substring-before($current/@points, ' '))"/> |
paul@19 | 350 | <xsl:with-param name="points" select="substring-after($current/@points, ' ')"/> |
paul@19 | 351 | <xsl:with-param name="current" select="$current"/> |
paul@19 | 352 | <xsl:with-param name="style" select="$style"/> |
paul@19 | 353 | </xsl:call-template> |
paul@19 | 354 | </xsl:when> |
paul@19 | 355 | <xsl:otherwise> |
paul@19 | 356 | <xsl:call-template name="node-outline"> |
paul@19 | 357 | <xsl:with-param name="path-so-far" select="$path-so-far"/> |
paul@19 | 358 | <xsl:with-param name="current" select="$current/following-sibling::*[1]"/> |
paul@19 | 359 | <xsl:with-param name="style" select="$style"/> |
paul@19 | 360 | </xsl:call-template> |
paul@19 | 361 | </xsl:otherwise> |
paul@19 | 362 | </xsl:choose> |
paul@19 | 363 | </xsl:when> |
paul@19 | 364 | <!-- With no more elements to visit, generate the path. --> |
paul@19 | 365 | <xsl:otherwise> |
paul@19 | 366 | <xsl:choose> |
paul@19 | 367 | <xsl:when test="$style = 'shadow'"> |
paul@19 | 368 | <path style="fill: black; stroke: none; fill-opacity:0.15" transform="translate(3,3)" |
paul@19 | 369 | d="{$path-so-far}"/> |
paul@19 | 370 | </xsl:when> |
paul@19 | 371 | <xsl:otherwise> |
paul@19 | 372 | <!-- Provide the path attributes using dynamic colour discoveries. --> |
paul@19 | 373 | <xsl:element name="path"> |
paul@19 | 374 | <xsl:attribute name="d"><xsl:value-of select="$path-so-far"/></xsl:attribute> |
paul@19 | 375 | <xsl:call-template name="make-style-attribute"> |
paul@19 | 376 | <xsl:with-param name="fill" |
paul@19 | 377 | select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'fill:'))"/> |
paul@19 | 378 | <xsl:with-param name="fill-explicit" |
paul@19 | 379 | select="@fill"/> |
paul@19 | 380 | <xsl:with-param name="stroke" |
paul@19 | 381 | select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'stroke:'))"/> |
paul@19 | 382 | <xsl:with-param name="stroke-explicit">black</xsl:with-param> |
paul@19 | 383 | <xsl:with-param name="none-is-transparent" select="true()"/> |
paul@19 | 384 | </xsl:call-template> |
paul@19 | 385 | </xsl:element> |
paul@19 | 386 | </xsl:otherwise> |
paul@19 | 387 | </xsl:choose> |
paul@19 | 388 | </xsl:otherwise> |
paul@19 | 389 | </xsl:choose> |
paul@19 | 390 | </xsl:template> |
paul@19 | 391 | |
paul@19 | 392 | <xsl:template name="filter-path"> |
paul@19 | 393 | <xsl:param name="path-so-far"/> |
paul@19 | 394 | <xsl:param name="point"/> |
paul@19 | 395 | <xsl:param name="points"/> |
paul@19 | 396 | <xsl:param name="current"/> |
paul@19 | 397 | <xsl:param name="style"/> |
paul@19 | 398 | |
paul@19 | 399 | <xsl:variable name="next" select="substring-before($points, ' ')"/> |
paul@19 | 400 | <xsl:variable name="remaining" select="substring-after($points, ' ')"/> |
paul@19 | 401 | |
paul@19 | 402 | <xsl:choose> |
paul@19 | 403 | <!-- With path points remaining, include the current point if appropriate |
paul@19 | 404 | and visit those remaining. --> |
paul@19 | 405 | <xsl:when test="$remaining"> |
paul@21 | 406 | <xsl:call-template name="filter-path"> |
paul@21 | 407 | <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point)"/> |
paul@21 | 408 | <xsl:with-param name="point" select="$next"/> |
paul@21 | 409 | <xsl:with-param name="points" select="$remaining"/> |
paul@21 | 410 | <xsl:with-param name="current" select="$current"/> |
paul@21 | 411 | <xsl:with-param name="style" select="$style"/> |
paul@21 | 412 | </xsl:call-template> |
paul@19 | 413 | </xsl:when> |
paul@19 | 414 | <!-- With up to one remaining after this point, include the current point, |
paul@19 | 415 | if appropriate, and the one remaining. --> |
paul@19 | 416 | <xsl:otherwise> |
paul@21 | 417 | <xsl:call-template name="node-outline"> |
paul@21 | 418 | <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point, ' ', $points)"/> |
paul@21 | 419 | <xsl:with-param name="current" select="$current/following-sibling::*[1]"/> |
paul@21 | 420 | <xsl:with-param name="style" select="$style"/> |
paul@21 | 421 | <xsl:with-param name="last" select="$current"/> |
paul@21 | 422 | </xsl:call-template> |
paul@19 | 423 | </xsl:otherwise> |
paul@19 | 424 | </xsl:choose> |
paul@19 | 425 | </xsl:template> |
paul@19 | 426 | |
paul@19 | 427 | <xsl:template name="polyline-to-path"> |
paul@19 | 428 | <xsl:param name="path-so-far"/> |
paul@19 | 429 | <xsl:param name="point"/> |
paul@19 | 430 | <xsl:param name="points"/> |
paul@19 | 431 | <xsl:param name="current"/> |
paul@19 | 432 | <xsl:param name="style"/> |
paul@19 | 433 | |
paul@19 | 434 | <xsl:variable name="next" select="substring-before($points, ' ')"/> |
paul@19 | 435 | <xsl:variable name="remaining" select="substring-after($points, ' ')"/> |
paul@19 | 436 | |
paul@19 | 437 | <xsl:choose> |
paul@19 | 438 | <!-- With path points remaining, include the current point if appropriate |
paul@19 | 439 | and visit those remaining. --> |
paul@19 | 440 | <xsl:when test="$remaining"> |
paul@21 | 441 | <xsl:call-template name="polyline-to-path"> |
paul@21 | 442 | <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point)"/> |
paul@21 | 443 | <xsl:with-param name="point" select="concat('L', $next)"/> |
paul@21 | 444 | <xsl:with-param name="points" select="$remaining"/> |
paul@21 | 445 | <xsl:with-param name="current" select="$current"/> |
paul@21 | 446 | <xsl:with-param name="style" select="$style"/> |
paul@21 | 447 | </xsl:call-template> |
paul@19 | 448 | </xsl:when> |
paul@19 | 449 | <!-- With up to one remaining after this point, include the current point, |
paul@19 | 450 | if appropriate, and the one remaining. --> |
paul@19 | 451 | <xsl:otherwise> |
paul@21 | 452 | <xsl:call-template name="node-outline"> |
paul@21 | 453 | <xsl:with-param name="path-so-far" select="concat($path-so-far, ' ', $point, ' L', $points)"/> |
paul@21 | 454 | <xsl:with-param name="current" select="$current/following-sibling::*[1]"/> |
paul@21 | 455 | <xsl:with-param name="style" select="$style"/> |
paul@21 | 456 | <xsl:with-param name="last" select="$current"/> |
paul@21 | 457 | </xsl:call-template> |
paul@19 | 458 | </xsl:otherwise> |
paul@19 | 459 | </xsl:choose> |
paul@19 | 460 | </xsl:template> |
paul@19 | 461 | |
paul@19 | 462 | <xsl:template name="poly-shadow"> |
paul@19 | 463 | <xsl:element name="{name()}"> |
paul@19 | 464 | <xsl:apply-templates select="@*"/> |
paul@19 | 465 | <xsl:attribute name="style">fill: black; stroke: none; fill-opacity:0.3</xsl:attribute> |
paul@19 | 466 | <xsl:attribute name="transform">translate(3,3)</xsl:attribute> |
paul@19 | 467 | </xsl:element> |
paul@19 | 468 | </xsl:template> |
paul@19 | 469 | |
paul@19 | 470 | <xsl:template name="path-shadow-edge"> |
paul@19 | 471 | <xsl:element name="{name()}"> |
paul@19 | 472 | <xsl:apply-templates select="@*"/> |
paul@19 | 473 | <xsl:attribute name="style">fill: none; stroke: black; stroke-opacity:0.3</xsl:attribute> |
paul@19 | 474 | <xsl:attribute name="transform">translate(3,3)</xsl:attribute> |
paul@19 | 475 | </xsl:element> |
paul@19 | 476 | </xsl:template> |
paul@19 | 477 | |
paul@19 | 478 | <xsl:template name="poly-main"> |
paul@19 | 479 | <xsl:element name="{name()}"> |
paul@19 | 480 | <xsl:apply-templates select="@*" /> |
paul@19 | 481 | <xsl:call-template name="make-style-attribute"> |
paul@19 | 482 | <xsl:with-param name="fill" |
paul@19 | 483 | select="normalize-space(substring-after(substring-before(@style,';'),'fill:'))"/> |
paul@19 | 484 | <xsl:with-param name="fill-explicit" |
paul@19 | 485 | select="@fill"/> |
paul@19 | 486 | <xsl:with-param name="stroke" |
paul@19 | 487 | select="normalize-space(substring-after(substring-after(@style,';'),'stroke:'))"/> |
paul@19 | 488 | <xsl:with-param name="stroke-explicit" |
paul@19 | 489 | select="@stroke"/> |
paul@19 | 490 | </xsl:call-template> |
paul@19 | 491 | </xsl:element> |
paul@19 | 492 | </xsl:template> |
paul@19 | 493 | |
paul@19 | 494 | <xsl:template name="path-main"> |
paul@19 | 495 | <path> |
paul@19 | 496 | <xsl:apply-templates select="@*" /> |
paul@19 | 497 | <!-- This is somewhat broken - the gradient is set based on the position/size of the element it is used with; as a result it doesn't line up properly with the main polygon --> |
paul@19 | 498 | <xsl:call-template name="make-style-attribute"> |
paul@19 | 499 | <xsl:with-param name="fill" |
paul@19 | 500 | select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'fill:'))"/> |
paul@19 | 501 | <xsl:with-param name="fill-explicit" |
paul@19 | 502 | select="ancestor::*[svg:polygon]/svg:polygon[1]/@fill"/> |
paul@19 | 503 | <xsl:with-param name="stroke" |
paul@19 | 504 | select="normalize-space(substring-after(substring-before(ancestor::*[svg:polygon]/svg:polygon[1]/@style,';'),'stroke:'))"/> |
paul@19 | 505 | <xsl:with-param name="stroke-explicit">black</xsl:with-param> |
paul@19 | 506 | </xsl:call-template> |
paul@19 | 507 | </path> |
paul@19 | 508 | </xsl:template> |
paul@19 | 509 | |
paul@19 | 510 | <xsl:template name="make-style-attribute"> |
paul@19 | 511 | <xsl:param name="fill"/> |
paul@19 | 512 | <xsl:param name="fill-explicit"/> |
paul@19 | 513 | <xsl:param name="stroke"/> |
paul@19 | 514 | <xsl:param name="stroke-explicit"/> |
paul@19 | 515 | <xsl:param name="none-is-transparent" select="false()"/> |
paul@19 | 516 | |
paul@19 | 517 | <xsl:attribute name="style"> |
paul@19 | 518 | <xsl:choose> |
paul@19 | 519 | <xsl:when test="$fill and (not($none-is-transparent) or $fill != 'none')"> |
paul@19 | 520 | <xsl:call-template name="make-style-fill"> |
paul@19 | 521 | <xsl:with-param name="fill" select="$fill"/> |
paul@19 | 522 | </xsl:call-template> |
paul@19 | 523 | </xsl:when> |
paul@19 | 524 | <xsl:when test="$fill-explicit and (not($none-is-transparent) or $fill-explicit != 'none')"> |
paul@19 | 525 | <xsl:choose> |
paul@19 | 526 | <xsl:when test="starts-with($fill-explicit, '#')"> |
paul@19 | 527 | <xsl:call-template name="make-style-fill"> |
paul@19 | 528 | <xsl:with-param name="fill" select="$fill-explicit"/> |
paul@19 | 529 | </xsl:call-template> |
paul@19 | 530 | </xsl:when> |
paul@19 | 531 | <xsl:otherwise>fill: url(#<xsl:value-of select="$fill-explicit"/>);</xsl:otherwise> |
paul@19 | 532 | </xsl:choose> |
paul@19 | 533 | </xsl:when> |
paul@19 | 534 | <xsl:otherwise>fill: none;</xsl:otherwise> |
paul@19 | 535 | </xsl:choose> |
paul@19 | 536 | <xsl:choose> |
paul@19 | 537 | <xsl:when test="$stroke">stroke: <xsl:value-of select="$stroke"/>;</xsl:when> |
paul@19 | 538 | <xsl:when test="$stroke-explicit">stroke: <xsl:value-of select="$stroke-explicit"/>;</xsl:when> |
paul@19 | 539 | <xsl:otherwise>stroke: black;</xsl:otherwise> |
paul@19 | 540 | </xsl:choose> |
paul@19 | 541 | </xsl:attribute> |
paul@19 | 542 | </xsl:template> |
paul@19 | 543 | |
paul@19 | 544 | <xsl:template name="make-style-fill"> |
paul@19 | 545 | <xsl:param name="fill"/> |
paul@19 | 546 | <xsl:choose> |
paul@19 | 547 | <xsl:when test="substring($fill,1,1) = '#'">fill: url(#fill-<xsl:value-of select="substring($fill,2,6)"/>);</xsl:when> |
paul@19 | 548 | <xsl:otherwise>fill: url(#<xsl:value-of select="$fill"/>);</xsl:otherwise> |
paul@19 | 549 | </xsl:choose> |
paul@19 | 550 | </xsl:template> |
paul@19 | 551 | |
paul@19 | 552 | </xsl:stylesheet> |