|
1 <?xml version="1.0"?> |
|
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/2000/svg" xmlns:s="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:exslt="http://exslt.org/common" exclude-result-prefixes="s exslt" > |
|
3 |
|
4 <!-- title of the model --> |
|
5 <xsl:template mode="title" match="SystemDefinition"> |
|
6 <title> |
|
7 <xsl:call-template name="title-line1"/> |
|
8 <xsl:variable name="t2"><xsl:call-template name="title-line2"/></xsl:variable> |
|
9 <xsl:variable name="t3"><xsl:call-template name="title-line3"/></xsl:variable> |
|
10 <xsl:if test="$t2!=''"><xsl:value-of select="concat(' ',$t2)"/></xsl:if> |
|
11 <xsl:if test="$t3!=''"><xsl:value-of select="concat(': ',$t3)"/></xsl:if> |
|
12 </title> |
|
13 </xsl:template> |
|
14 |
|
15 |
|
16 |
|
17 <xsl:template match="meta[@rel='model-logo']" mode="global"> |
|
18 <xsl:param name="bottom"/> |
|
19 <xsl:for-each select="logo"> |
|
20 <g class="logo"> |
|
21 <xsl:attribute name="transform">translate(0 <xsl:value-of select="$bottom"/>) <xsl:if test="@viewBox"> |
|
22 <xsl:variable name="b" select="normalize-space(@viewBox)"/> |
|
23 <xsl:variable name="x0" select="- number(substring-before($b,' '))"/> |
|
24 <xsl:variable name="y0" select="- number(substring-before(substring-after($b,' '),' '))"/> |
|
25 <xsl:variable name="x1" select="number(substring-before(substring-after(substring-after($b,' '),' '),' '))"/> |
|
26 <xsl:variable name="y1" select="number(substring-after(substring-after(substring-after($b,' '),' '),' '))"/> |
|
27 <xsl:text> scale(</xsl:text> |
|
28 <xsl:if test="@width"><xsl:value-of select="number(@width) div ($x1 + $x0)"/></xsl:if> |
|
29 <xsl:if test="@height"> |
|
30 <xsl:text> </xsl:text><xsl:value-of select="@height div ($y1 + $y0)"/> |
|
31 </xsl:if> |
|
32 <xsl:if test="not(@width | @height)">1</xsl:if> |
|
33 <xsl:text>)</xsl:text> |
|
34 <xsl:if test="not($x0=0 and $y0=0)"> translate(<xsl:value-of select="concat($x0,' ', $y0)"/>)</xsl:if> |
|
35 </xsl:if></xsl:attribute> |
|
36 <xsl:choose> |
|
37 <xsl:when test="@src"> |
|
38 <image x="0" y="0" width="{@width}" height="{@height}" xlink:href="{@src}"/> |
|
39 </xsl:when> |
|
40 <xsl:otherwise> |
|
41 <xsl:copy-of select="*"/> |
|
42 </xsl:otherwise> |
|
43 </xsl:choose> |
|
44 </g> |
|
45 </xsl:for-each> |
|
46 </xsl:template> |
|
47 |
|
48 <xsl:template match="meta[@rel='model-footer' and *]" mode="global"> |
|
49 <xsl:variable name="copyright"> |
|
50 <xsl:apply-templates select="ancestor::SystemDefinition/@copyright" mode="as-text"/> |
|
51 </xsl:variable> |
|
52 <xsl:variable name="distribution"> |
|
53 <xsl:apply-templates select="ancestor::SystemDefinition/@distribution" mode="as-text"/> |
|
54 </xsl:variable> |
|
55 <g class="footer" transform="translate(0 {ancestor::SystemDefinition/@height - @height})"> |
|
56 <xsl:if test="$copyright != '' and copyright"> |
|
57 <text text-anchor="start" class="lgd" x="0" y="{@height}" style="font-weight: normal"><xsl:value-of select="$copyright"/></text> |
|
58 </xsl:if> |
|
59 <xsl:if test="$distribution !='' and distribution"> |
|
60 <text text-anchor="middle" class="lgd" x="{ancestor::SystemDefinition/@width *0.5}" y="{@height}" style="font-weight: normal"><xsl:value-of select="$distribution"/></text> |
|
61 </xsl:if> |
|
62 </g> |
|
63 </xsl:template> |
|
64 |
|
65 |
|
66 <!-- |
|
67 Baisc rules: |
|
68 No <legend> means no legend will be generated and no title will appear |
|
69 An empty <legend/> means only the model title will appear. |
|
70 A legend with content will generate the legend as requested. The legend lable only appears if the legend has content |
|
71 --> |
|
72 <xsl:template match="meta[@rel='model-legend']" mode="global"> |
|
73 <xsl:param name="bottom"/> |
|
74 <xsl:variable name="lw" select="@width div @scaled"/> <!-- width of whole legend area without scaling --> |
|
75 <xsl:for-each select="legend"> |
|
76 <xsl:variable name="h" select="(@height | @min-height)"/> |
|
77 <xsl:variable name="w"> |
|
78 <xsl:apply-templates select="." mode="actual-width"> |
|
79 <xsl:with-param name="h" select="$h - @ipad"/> |
|
80 </xsl:apply-templates> |
|
81 </xsl:variable> |
|
82 |
|
83 <g id="legend-root" class="legend" transform="translate({ancestor::SystemDefinition/@width - $lw} {$bottom}) translate({$lw} {0}) scale({../@scaled}) translate({- $lw})"> |
|
84 |
|
85 <!-- draw the model title --> |
|
86 <xsl:apply-templates select="ancestor::SystemDefinition" mode="legend-label"> |
|
87 <xsl:with-param name="x" select="$lw - (@title-width * 0.5)"/> |
|
88 <xsl:with-param name="y" select="0"/> |
|
89 </xsl:apply-templates> |
|
90 |
|
91 <xsl:if test="*"> <!-- only draw if there is some legend content --> |
|
92 <g id="legend-box"><!-- legend-box is the rectangle container of all generated legend content (ie not the title)--> |
|
93 <xsl:if test="not(@static='true') and @float"> |
|
94 <xsl:attribute name="onmouseout">movelegend('legend-root')</xsl:attribute> |
|
95 </xsl:if> |
|
96 <rect class="legend" rx="{@ipad}" ry="{@ipad}" height="{$h}" width="{$w}" x="0" y="0"/> |
|
97 <g transform="translate({@ipad} {@ipad * 0.5})"> |
|
98 <xsl:apply-templates select="@label|*"> |
|
99 <xsl:with-param name="h" select="$h - @ipad"/> |
|
100 </xsl:apply-templates> |
|
101 </g> |
|
102 </g> |
|
103 </xsl:if> |
|
104 </g> |
|
105 <xsl:if test="not(@static='true') and @float"> |
|
106 <g id="legend-display" class="legend" transform="translate({ancestor::SystemDefinition/@width - $lw} {$bottom})" opacity="0.8"> |
|
107 <g id="legend-owner"> |
|
108 <rect id="legend-ctrl" rx="{@ipad}" ry="{@ipad}" height="{$h}" width="{$w}" x="0" y="0" visibility="hidden" pointer-events="all"> |
|
109 <xsl:attribute name="onmouseover">movelegend('legend-owner')</xsl:attribute> |
|
110 </rect> |
|
111 </g> |
|
112 </g> |
|
113 </xsl:if> |
|
114 </xsl:for-each> |
|
115 </xsl:template> |
|
116 |
|
117 |
|
118 <xsl:template match="@label"><xsl:param name="h"/> |
|
119 <text text-anchor="start" class="lgd" dy="0.375em" x="0"> |
|
120 <xsl:attribute name="y"><xsl:value-of select="$h div 2 "/></xsl:attribute> |
|
121 <xsl:for-each select=".."><xsl:call-template name="display-name"/></xsl:for-each> |
|
122 </text> |
|
123 </xsl:template> |
|
124 |
|
125 <xsl:template match="note"><xsl:param name="h"/> |
|
126 <xsl:variable name="off"> |
|
127 <xsl:apply-templates select="." mode="x-pos"> |
|
128 <xsl:with-param name="h" select="$h"/> |
|
129 </xsl:apply-templates> |
|
130 </xsl:variable> |
|
131 <xsl:variable name="newlines" select="string-length(.) - string-length(translate(.,'
',''))"/> |
|
132 <text text-anchor="middle" class="label" dy="0.375em" x="{$off + 0.5* @width}" y="{$h div 2}"> |
|
133 <xsl:copy-of select="@style|@class"/> |
|
134 <xsl:call-template name="multiline"> |
|
135 <xsl:with-param name="x" select="$off + 0.5* @width"/> |
|
136 <xsl:with-param name="n" select="-0.5 * $newlines"/> |
|
137 <xsl:with-param name="t"> |
|
138 <xsl:apply-templates select="." mode="eval-label"/> |
|
139 </xsl:with-param> |
|
140 </xsl:call-template> |
|
141 </text> |
|
142 </xsl:template> |
|
143 |
|
144 |
|
145 <xsl:template match="SystemDefinition" mode="legend-label"> |
|
146 <xsl:param name="x"/> |
|
147 <xsl:param name="y"/> |
|
148 <text text-anchor="middle" class="title" x="{$x}" y="{$y}"> |
|
149 <tspan dy="0.75em" x="{$x}"> |
|
150 <xsl:call-template name="title-line1"/> |
|
151 </tspan> |
|
152 <tspan dy="1em" x="{$x}"> |
|
153 <xsl:call-template name="title-line2"/> |
|
154 </tspan> |
|
155 <tspan font-style="italic" dy="1em" id="release-version" x="{$x}"> |
|
156 <!-- show nothing if nothing specified, but leave tspan in case later need for it --> |
|
157 <xsl:variable name="t3"><xsl:call-template name="title-line3"/></xsl:variable> |
|
158 <xsl:if test="@revision and starts-with($t3,'DRAFT') or (@revision-type and not(@revision))"> |
|
159 <!-- draft is in uppercase, but not bold font --> |
|
160 <!-- or if it's just the type with no value, put in non-bold font. --> |
|
161 <xsl:attribute name="font-weight">normal</xsl:attribute> |
|
162 </xsl:if> |
|
163 <xsl:value-of select="$t3"/> |
|
164 </tspan> |
|
165 </text> |
|
166 </xsl:template> |
|
167 |
|
168 |
|
169 |
|
170 <xsl:template match="legend|note" mode="x-pos"><xsl:param name="h"/> |
|
171 <xsl:variable name="x" select="sum(preceding-sibling::*/@width | preceding-sibling::*/@rpad | parent::legend[parent::meta]/@label-width)"/> |
|
172 <xsl:choose> |
|
173 <xsl:when test="preceding-sibling::*[not(@width)]"> |
|
174 <xsl:call-template name="sum-list"> |
|
175 <xsl:with-param name="list"> |
|
176 <xsl:value-of select="concat($x, ' ')"/> |
|
177 <xsl:for-each select="preceding-sibling::*[not(@width)]"> |
|
178 <xsl:apply-templates select="." mode="actual-width"> |
|
179 <xsl:with-param name="h" select="$h"/> |
|
180 </xsl:apply-templates> |
|
181 <xsl:text> </xsl:text> |
|
182 </xsl:for-each> |
|
183 </xsl:with-param> |
|
184 </xsl:call-template> |
|
185 </xsl:when> |
|
186 <xsl:otherwise> |
|
187 <xsl:value-of select="$x"/> |
|
188 </xsl:otherwise> |
|
189 </xsl:choose> |
|
190 </xsl:template> |
|
191 |
|
192 |
|
193 <xsl:template match="legend"><xsl:param name="h"/> |
|
194 <g> |
|
195 <xsl:attribute name="transform">translate(<xsl:apply-templates select="." mode="x-pos"> |
|
196 <xsl:with-param name="h" select="$h"/> |
|
197 </xsl:apply-templates> 0)</xsl:attribute> |
|
198 <xsl:variable name="name"><xsl:call-template name="name-value"/></xsl:variable> |
|
199 <xsl:if test="$name!=''"> |
|
200 <text text-anchor="end" class="label" dy="0.375em" x="{@label-width - 1.5}" y="{$h div 2}"> |
|
201 <xsl:attribute name="width"><xsl:value-of select="@label-width - 1.5"/></xsl:attribute> |
|
202 <xsl:if test="@font"><xsl:attribute name="style">font-family: '<xsl:value-of select="@font"/>'</xsl:attribute></xsl:if> |
|
203 <xsl:value-of select="$name"/>:</text> |
|
204 </xsl:if> |
|
205 <xsl:choose> |
|
206 <xsl:when test="@sort='yes'"> |
|
207 <xsl:apply-templates select="*| key('ldg-use',@use)/*[@lookup or @label]"> |
|
208 <xsl:sort select="concat(@label,@lookup)"/> |
|
209 <xsl:with-param name="h" select="$h"/> <!-- available height --> |
|
210 <xsl:with-param name="y" select="0"/> <!-- vertical offset --> |
|
211 </xsl:apply-templates> |
|
212 </xsl:when> |
|
213 <xsl:otherwise> |
|
214 <xsl:apply-templates select="*| key('ldg-use',@use)/*[@lookup or @label]"> |
|
215 <xsl:with-param name="h" select="$h"/> <!-- available height --> |
|
216 <xsl:with-param name="y" select="0"/> <!-- vertical offset --> |
|
217 </xsl:apply-templates> |
|
218 </xsl:otherwise> |
|
219 </xsl:choose> |
|
220 </g> |
|
221 </xsl:template> |
|
222 |
|
223 <xsl:template match="legend/cbox|group/cbox"><xsl:param name="h"/><!-- can only have one type per legend --> |
|
224 <xsl:variable name="rows" select="floor(($h+0.0001) div $cboxHeight)"/> <!-- avoid rounding errors --> |
|
225 <xsl:variable name="total" select="last()"/> |
|
226 <xsl:variable name="cols" select="ceiling($total div $rows)"/> |
|
227 <xsl:variable name="dy" select="($h - floor(1 + ($total - 1) div $cols) * $cboxHeight) div 2"/> |
|
228 <xsl:variable name="index" select="position() - 1"/> |
|
229 |
|
230 <g id="{@id|@style-id}"> |
|
231 <!-- id used for mouseover animations --> |
|
232 <rect class="cbox" height="{$cboxHeight}" width="{$cboxWidth}"> |
|
233 <xsl:apply-templates select="." mode="color"/> |
|
234 <xsl:attribute name="x"><xsl:value-of select="sum(../@label-width) + $cboxWidth * ($index mod $cols)"/></xsl:attribute> |
|
235 <xsl:attribute name="y"><xsl:value-of select="$dy + floor($index div $cols) * $cboxHeight"/></xsl:attribute> |
|
236 </rect> |
|
237 <text text-anchor="middle" class="cbox" width="{$cboxWidth}" dy="0.375em"> |
|
238 <xsl:attribute name="x"><xsl:value-of select="sum(../@label-width) + $cboxWidth * (($index mod $cols) + 0.5)"/></xsl:attribute> |
|
239 <xsl:attribute name="y"><xsl:value-of select="$dy + ( 0.5 + floor($index div $cols)) * $cboxHeight"/></xsl:attribute> |
|
240 <xsl:if test="@font"><xsl:attribute name="style">font-family: '<xsl:value-of select="@font"/>'</xsl:attribute></xsl:if> |
|
241 <xsl:apply-templates mode="name" select="."/> |
|
242 </text> |
|
243 </g> |
|
244 </xsl:template> |
|
245 |
|
246 |
|
247 <!-- for drawing generated legend items --> |
|
248 |
|
249 |
|
250 <xsl:template match="*" mode="color"><xsl:attribute name="fill"><xsl:value-of select="@color"/></xsl:attribute></xsl:template> |
|
251 <xsl:template match="cbox" mode="color"><xsl:attribute name="fill"><xsl:value-of select="@value"/></xsl:attribute></xsl:template> |
|
252 |
|
253 <xsl:template match="cbox" mode="id">color-<xsl:value-of select="concat(name(),'-',count(preceding::cbox))"/></xsl:template> |
|
254 <xsl:template match="cmp" mode="id">style-<xsl:value-of select="concat(name(),'-',count(preceding::cmp))"/></xsl:template> |
|
255 <xsl:template match="*[@style-id]" mode="id"><xsl:value-of select="concat(name(),'-',@style-id)"/></xsl:template> |
|
256 |
|
257 |
|
258 |
|
259 <xsl:template match="cmp" mode="display-style"> |
|
260 <xsl:variable name="color"><xsl:apply-templates select="." mode="display-style-color"/></xsl:variable> |
|
261 <xsl:if test="$color!=''">fill:<xsl:value-of select="$color"/>;</xsl:if> |
|
262 <xsl:for-each select="@generated-style | generated-style/@value"><xsl:value-of select="."/>;</xsl:for-each> |
|
263 <xsl:apply-templates select="." mode="display-style-aux"/> |
|
264 </xsl:template> |
|
265 |
|
266 <xsl:template match="cmp[@generated-color]" mode="display-style-color" priority="8"><!-- colour in legend --> |
|
267 <xsl:value-of select="@generated-color"/> |
|
268 </xsl:template> |
|
269 |
|
270 <xsl:template match="cmp[@generated-overlay|generated-overlay]" mode="overlays" priority="8"> |
|
271 <xsl:for-each select="@generated-overlay|generated-overlay/@ref"> |
|
272 <o><xsl:value-of select="."/></o> |
|
273 </xsl:for-each> |
|
274 </xsl:template> |
|
275 |
|
276 <xsl:template match="cmp[@generated-border]" mode="shape" priority="8"> |
|
277 <xsl:value-of select="@generated-border"/> |
|
278 </xsl:template> |
|
279 |
|
280 <xsl:template match="cmp[@generated-text-highlight]" mode="text-filter" priority="8"> |
|
281 <xsl:attribute name="filter">url(<xsl:value-of select="@generated-text-highlight"/>)</xsl:attribute> |
|
282 </xsl:template> |
|
283 |
|
284 <xsl:template match="cmp[@generated-highlight]" mode="filter" priority="8"> |
|
285 <xsl:attribute name="filter">url(<xsl:value-of select="@generated-highlight"/>)</xsl:attribute> |
|
286 </xsl:template> |
|
287 |
|
288 |
|
289 <xsl:template match="group[@type='border']/cmp[@value]" mode="shape"> |
|
290 <xsl:value-of select="@value"/> |
|
291 </xsl:template> |
|
292 |
|
293 <xsl:template match="group[@type='overlay']/cmp[@value]" mode="overlays"> |
|
294 <o><xsl:value-of select="@value"/></o> |
|
295 </xsl:template> |
|
296 |
|
297 <xsl:template match="group[@type='style']/cmp[@value]" mode="display-style-aux" priority="6"> |
|
298 <xsl:value-of select="@value"/>;</xsl:template> |
|
299 |
|
300 <xsl:template match="group[@type='text-highlight']/cmp[@value]" mode="text-filter" priority="8"> |
|
301 <xsl:attribute name="filter">url(<xsl:value-of select="@value"/>)</xsl:attribute> |
|
302 </xsl:template> |
|
303 |
|
304 <xsl:template match="group[@type='highlight']/cmp[@value]" mode="filter" priority="8"> |
|
305 <xsl:attribute name="filter">url(<xsl:value-of select="@value"/>)</xsl:attribute> |
|
306 </xsl:template> |
|
307 |
|
308 |
|
309 <!-- end legend items --> |
|
310 |
|
311 <xsl:template name="multiline"> <!-- draw text with newlines --> |
|
312 <xsl:param name="x" select="0"/> <!-- anchor point --> |
|
313 <xsl:param name="n" select="1"/> <!-- spacing: default is single-spaced --> |
|
314 <xsl:param name="t" select="."/> <!-- the text to draw --> |
|
315 <xsl:choose> |
|
316 <xsl:when test="contains($t,'
')"> |
|
317 <tspan dy="{$n}em" x="{$x}"> |
|
318 <xsl:value-of select="normalize-space(substring-before($t,'
'))"/></tspan> |
|
319 <xsl:call-template name="multiline"> |
|
320 <xsl:with-param name="x" select="$x"/> |
|
321 <xsl:with-param name="t" select="substring-after($t,'
')"/> |
|
322 </xsl:call-template> |
|
323 </xsl:when> |
|
324 <xsl:otherwise> |
|
325 <tspan dy="{$n}em" x="{$x}"><xsl:value-of select="normalize-space($t)"/></tspan> |
|
326 </xsl:otherwise> |
|
327 </xsl:choose> |
|
328 </xsl:template> |
|
329 |
|
330 |
|
331 </xsl:stylesheet> |
|
332 |
|
333 |