sysmodellibs/sysmodelgen/src/old/svg/Legend.xsl
changeset 6 5b32dc297d05
parent 1 b538b70cbe51
equal deleted inserted replaced
3:e7e0ae78773e 6:5b32dc297d05
       
     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 	  <xsl:key name="style-ref" match="*[starts-with(name(),'generator-')]/@ref| @*[starts-with(name(),'generator-')]" use="."/>
       
     5 
       
     6 	<xsl:variable name="cboxWidth" select="15.5"/>
       
     7 	<xsl:variable name="cboxHeight" select="3.1"/>
       
     8 
       
     9 <!-- title of the model -->
       
    10 <xsl:template mode="title" match="systemModel">
       
    11 	<title>
       
    12 		<xsl:call-template name="title-line1"/>
       
    13 		<xsl:variable name="t2"><xsl:call-template name="title-line2"/></xsl:variable>
       
    14 		<xsl:variable name="t3"><xsl:call-template name="title-line3"/></xsl:variable>		
       
    15 		<xsl:if test="$t2!=''"><xsl:value-of select="concat(' ',$t2)"/></xsl:if>
       
    16 		<xsl:if test="$t3!=''"><xsl:value-of select="concat(': ',$t3)"/></xsl:if>
       
    17 	</title>
       
    18 </xsl:template>
       
    19 
       
    20 <!-- legend stuff -->
       
    21 
       
    22 <xsl:template match="legend-layer" mode="height">
       
    23 	<xsl:variable name="h1"> <!-- height of generated legend content -->
       
    24 		<xsl:choose>
       
    25 			<!-- strip out all unused legend items if possible -->
       
    26 			<xsl:when test="function-available('exslt:node-set') and parent::systemModel">
       
    27 				 <xsl:variable name="Legend">
       
    28 					 <xsl:apply-templates select="/SystemDefinition/systemModel/legend-layer" mode="legend-copy"/>
       
    29 				 </xsl:variable>
       
    30 		 		<xsl:apply-templates select="exslt:node-set($Legend)/descendant-or-self::legend-layer" mode="content-height"/>
       
    31 			</xsl:when>
       
    32 			<xsl:otherwise><xsl:apply-templates select="." mode="content-height"/></xsl:otherwise>
       
    33 		</xsl:choose>
       
    34 	</xsl:variable> <!-- $h1 does not take into account scaling the legend content -->
       
    35 
       
    36 	<!-- $h2 is height of single line in legend title -->
       
    37 	<xsl:variable name="h2"><xsl:call-template name="title-line-height"/></xsl:variable>
       
    38 	<xsl:variable name="hl"><xsl:apply-templates select="../logo" mode="height"/></xsl:variable>	
       
    39 	<xsl:variable name="h3">
       
    40 		<xsl:choose>
       
    41 			<xsl:when test="$hl='' or $hl='?'">0</xsl:when>	<!-- no logo or unknown height -->
       
    42 			<xsl:otherwise><xsl:value-of select="$hl"/></xsl:otherwise>
       
    43 		</xsl:choose>
       
    44 	</xsl:variable>	
       
    45 
       
    46 	<xsl:variable name="h"> <!-- $h is max of $h1 and 3*$h2 -->
       
    47 		<xsl:choose>
       
    48 			<xsl:when test="3 * $h2 &gt;= $h1 and 3* $h2 &gt;= $h3"><xsl:value-of select="3* $h2"/></xsl:when>
       
    49 			<xsl:when test="$h3 &gt;= $h1"><xsl:value-of select="$h3"/></xsl:when>
       
    50 			<xsl:otherwise><xsl:value-of select="$h1"/></xsl:otherwise>
       
    51 		</xsl:choose>
       
    52 	</xsl:variable>	
       
    53 	<xsl:variable name="copyheight">
       
    54 		<xsl:choose>
       
    55 		<xsl:when test="@footer"><xsl:value-of select="$legendDx * 3 + 4.233"/></xsl:when>
       
    56 		<xsl:otherwise>0</xsl:otherwise>
       
    57 		</xsl:choose>
       
    58 	</xsl:variable>
       
    59 	<xsl:value-of select="$h +  $copyheight"/>
       
    60 </xsl:template>
       
    61 
       
    62 
       
    63 <xsl:template match="legend-layer" mode="content-height"> <!-- only called from mode="height" -->
       
    64 	<xsl:variable name="h">
       
    65 		<xsl:call-template name="max-from-list">
       
    66 			<xsl:with-param name="list">
       
    67 				<xsl:text>4.233 </xsl:text>
       
    68 				<xsl:for-each select="legend"><xsl:apply-templates select="." mode="min-height"/><xsl:text>  </xsl:text></xsl:for-each>
       
    69 			</xsl:with-param>
       
    70 		</xsl:call-template>
       
    71 	</xsl:variable>
       
    72 	<xsl:value-of select="$h +  $legendDx"/>
       
    73 </xsl:template>
       
    74 
       
    75 
       
    76 
       
    77 <xsl:template match="legend-layer" mode="width">
       
    78 	<xsl:choose>
       
    79 		<!-- strip out all unused legend items if possible -->
       
    80 		<xsl:when test="function-available('exslt:node-set') and parent::systemModel">
       
    81 			 <xsl:variable name="Legend">
       
    82 				 <xsl:apply-templates select="/SystemDefinition/systemModel/legend-layer" mode="legend-copy"/>
       
    83 			 </xsl:variable>
       
    84 	 		<xsl:apply-templates select="exslt:node-set($Legend)/descendant-or-self::legend-layer" mode="width-detail"/>
       
    85 		</xsl:when>
       
    86 		<xsl:otherwise><xsl:apply-templates select="." mode="width-detail"/></xsl:otherwise>
       
    87 	</xsl:choose>
       
    88 </xsl:template>
       
    89 
       
    90 <xsl:template match="legend-layer[not(@label) and not(*)]" mode="width">0</xsl:template> <!-- no content -->
       
    91 
       
    92 
       
    93 <xsl:template match="legend-layer" mode="width-detail">
       
    94 	<xsl:variable name="x">
       
    95 		<xsl:apply-templates select="*[last()]" mode="offset"/>
       
    96 	</xsl:variable>
       
    97 	<xsl:variable name="w">
       
    98 		<xsl:apply-templates select="*[last()]" mode="width"/>
       
    99 	</xsl:variable>
       
   100 	<xsl:choose>
       
   101 		<xsl:when test="not(*)"><xsl:apply-templates select="@label" mode="width"/></xsl:when>
       
   102 		<xsl:when test="$w=0"><xsl:value-of select="$x"/></xsl:when>
       
   103 		<xsl:otherwise><xsl:value-of select="$legendDx + $x + $w"/></xsl:otherwise>
       
   104 	</xsl:choose>
       
   105 </xsl:template>
       
   106 
       
   107 <xsl:template match="legend" mode="width" priority="-2">100</xsl:template>
       
   108 <xsl:template match="legend[not(*) and not(@*)]" mode="width" priority="5">0</xsl:template> <!-- empty: ignore -->
       
   109 
       
   110 <xsl:template match="@label" mode="width"><xsl:value-of select="string-length(.) *  4"/></xsl:template>
       
   111 <xsl:template match="note" mode="width">20</xsl:template>
       
   112 <xsl:template match="note[@width]" mode="width" priority="1">
       
   113 	<xsl:value-of select="@width"/>
       
   114 </xsl:template>
       
   115 <xsl:template match="@label[../@label-ref]" mode="width">
       
   116 	<xsl:variable name="text"><xsl:apply-templates mode="name" select=".."/></xsl:variable>
       
   117 	<xsl:value-of select="string-length($text) *  4"/>
       
   118 </xsl:template>
       
   119 
       
   120 <xsl:template match="note[@width='auto']" mode="width" priority="2">
       
   121 	<xsl:variable name="len"><xsl:call-template name="multiline-width"/></xsl:variable>
       
   122 	<xsl:variable name="h">
       
   123 		<xsl:choose>
       
   124 			<xsl:when test="@class='lgd'">4.233</xsl:when>
       
   125 			<xsl:otherwise>1.94</xsl:otherwise>
       
   126 		</xsl:choose>
       
   127 	</xsl:variable>
       
   128 	<!--  the width is a guess based on the half the (expected) font size + a border of 2.5 on each side-->
       
   129 		<xsl:value-of select="5 + $len * 0.5 * $h"/>
       
   130 </xsl:template>
       
   131 
       
   132 
       
   133 <xsl:template match="legend|note" mode="offset">
       
   134 	<xsl:variable name="x">
       
   135 		<xsl:apply-templates select="preceding-sibling::*[1]" mode="offset"/>
       
   136 	</xsl:variable>
       
   137 	<xsl:variable name="w">
       
   138 		<xsl:apply-templates select="preceding-sibling::*[1]" mode="width"/>
       
   139 	</xsl:variable>
       
   140 
       
   141 	<xsl:choose>
       
   142 		<xsl:when test="not(preceding-sibling::*) and ../@label"><xsl:apply-templates select="../@label" mode="width"/></xsl:when>
       
   143 		<xsl:when test="not(preceding-sibling::*)">0</xsl:when>
       
   144 		<xsl:when test="$w=0"><xsl:value-of select="$x"/></xsl:when>
       
   145 		<xsl:otherwise><xsl:value-of select="$legendDx + $x + $w"/></xsl:otherwise>
       
   146 	</xsl:choose>
       
   147 </xsl:template>
       
   148 
       
   149 
       
   150 <xsl:template match="legend-layer"><xsl:param name="y" select="0"/>
       
   151 <!--
       
   152 	 <xsl:apply-templates select="/SystemDefinition/systemModel/legend-layer" mode="legend-copy"/>
       
   153   -->	 
       
   154 	<xsl:choose>
       
   155 		<!-- strip out all unused legend items if possible -->
       
   156 		<xsl:when test="function-available('exslt:node-set')">
       
   157 			 <xsl:variable name="Legend">
       
   158 				 <xsl:apply-templates select="/SystemDefinition/systemModel/legend-layer" mode="legend-copy"/>
       
   159 			 </xsl:variable>
       
   160 			<xsl:variable name="parent" select="parent::systemModel"/>
       
   161 	 		<xsl:apply-templates select="exslt:node-set($Legend)/descendant-or-self::legend-layer" mode="legend-detail">
       
   162 				<xsl:with-param name="y" select="$y"/>
       
   163 				<xsl:with-param name="model" select="$parent"/>
       
   164 			</xsl:apply-templates>	
       
   165 		</xsl:when>
       
   166 		<xsl:otherwise>
       
   167 			<!-- go the long way -->
       
   168 			<xsl:apply-templates select="." mode="legend-detail">
       
   169 				<xsl:with-param name="y" select="$y"/>
       
   170 				<xsl:with-param name="model" select="parent::systemModel"/>
       
   171 			</xsl:apply-templates>
       
   172 		</xsl:otherwise>
       
   173 	</xsl:choose>
       
   174 </xsl:template>
       
   175 
       
   176 <xsl:template name="title-line-height">
       
   177 	<xsl:choose>
       
   178 		<xsl:when test="number(/SystemDefinition/systemModel/legend-layer/@title-scale)">
       
   179 			<xsl:value-of select="4.3 * /SystemDefinition/systemModel/legend-layer/@title-scale"/> <!-- scale 12pt by specified factor-->
       
   180 		</xsl:when>
       
   181 		<xsl:when test="/SystemDefinition/systemModel/legend-layer[@width or @maxscale]">4.233</xsl:when> <!-- 12pt -->
       
   182 		<xsl:when test="$full-width &gt; $large-width">6.3495</xsl:when> <!-- 18 pt -->
       
   183 		<xsl:otherwise>4.3</xsl:otherwise> <!-- 12pt -->
       
   184 	</xsl:choose>		
       
   185 </xsl:template>
       
   186 
       
   187 <xsl:template match="legend-layer" mode="legend-detail"><xsl:param name="y" select="0"/>
       
   188 	<xsl:param name="model"/>
       
   189 	<xsl:variable name="h"><xsl:apply-templates select="." mode="content-height"/></xsl:variable>
       
   190 	<xsl:variable name="w"><xsl:apply-templates select="." mode="width"/></xsl:variable>
       
   191 	<xsl:variable name="titleW"><xsl:apply-templates select="$model" mode="legend-title-width"/></xsl:variable>
       
   192 	<xsl:variable name="wl"><xsl:apply-templates select="$model/logo" mode="width"/></xsl:variable>	
       
   193 	<xsl:variable name="available-width"> <!--  amount of space of legend -->
       
   194 		<xsl:choose>
       
   195 			<xsl:when test="$wl=''"><xsl:value-of select="$full-width + 12.8"/></xsl:when> <!-- no logo -->
       
   196 			<xsl:otherwise><xsl:value-of select="$full-width + 12.8 -  $wl"/></xsl:otherwise> <!--  logo -->
       
   197 		</xsl:choose>
       
   198 	</xsl:variable>	
       
   199 	<xsl:variable name="want-width">
       
   200 		<xsl:choose>
       
   201 			<xsl:when test="contains(@width,'%')"><xsl:value-of select="0.01* substring-before(@width,'%') * $available-width"/></xsl:when>
       
   202 			<xsl:otherwise><xsl:value-of select="$available-width"/></xsl:otherwise>
       
   203 		</xsl:choose>
       
   204 	</xsl:variable>	
       
   205 	<xsl:variable name="scale">
       
   206 		<xsl:choose>
       
   207 			<xsl:when test="@maxscale  and ($want-width &gt; ($w+$titleW) * @maxscale)"><xsl:value-of select="@maxscale"/></xsl:when> <!--  -->
       
   208 			<xsl:when test="@maxscale or @width"><xsl:value-of select="$want-width div ($w+$titleW)"/></xsl:when>
       
   209 			<xsl:otherwise>1</xsl:otherwise>
       
   210 		</xsl:choose>
       
   211 	</xsl:variable>
       
   212 	<!-- legend-root is the root of all legend content, including the title -->
       
   213 	<g id="legend-root" class="legend" transform="translate({$full-width + 12.8 - $titleW - $w} {$y}) translate({$w + $titleW} {$scale*5 - 5}) scale({$scale}) translate({- $w - $titleW})">
       
   214 		<xsl:apply-templates select="$model" mode="legend-label">
       
   215 			<xsl:with-param name="x" select="$w + ($titleW * 0.5)"/>
       
   216 			<xsl:with-param name="y" select="($h - $legendDx) * 0.5"/>
       
   217 		</xsl:apply-templates>
       
   218 			<xsl:if test="*"> <!-- only draw if there is some legend content -->
       
   219 				<g id="legend-box"><!-- legend-box is the rectangle container of all geenrated legend content (ie not the title)-->
       
   220 					<rect class="legend" rx="{$legendDx}" ry="{$legendDx}" height="{$h}" width="{$w +  $legendDx}" x="0" y="0"/>
       
   221 					<g transform="translate({concat($legendDx,' ',$legendDx * 0.5)})">
       
   222 						<xsl:apply-templates select="@label|*">
       
   223 							<xsl:with-param name="h" select="$h - $legendDx"/>
       
   224 						</xsl:apply-templates>		
       
   225 					</g>
       
   226 				</g>
       
   227 			</xsl:if>
       
   228 		</g>	
       
   229 	<xsl:variable name="copyright">
       
   230 		<xsl:apply-templates select="$model/@copyright"/>	
       
   231 	</xsl:variable>
       
   232 	<xsl:variable name="distribution">
       
   233 		<xsl:apply-templates select="$model/@distribution"/>	
       
   234 	</xsl:variable>
       
   235 	<xsl:if test="@footer">
       
   236 		<xsl:variable name="foot" select="concat(' ',@footer,' ')"/>
       
   237 		<g transform="translate({concat('0 ',$y + $h + $legendDx )})">
       
   238 			<xsl:if test="$copyright != '' and contains($foot,' copyright ')">
       
   239 				<text text-anchor="start" class="lgd" x="0" y="0" style="font-weight: normal"><xsl:value-of select="$copyright"/></text>
       
   240 			</xsl:if>
       
   241 			<xsl:if test="$distribution !='' and contains($foot,' distribution ')">
       
   242 				<text text-anchor="middle" class="lgd" x="{$view-width*0.5 - $groupDy}" y="0" style="font-weight: normal"><xsl:value-of select="$distribution"/></text>
       
   243 			</xsl:if>
       
   244 		</g>
       
   245 	</xsl:if>
       
   246 	<xsl:apply-templates select="preceding-sibling::*[1]">
       
   247 		<xsl:with-param name="y" select="$y + $h + $groupDy"/>
       
   248 	</xsl:apply-templates>
       
   249 	<g id="legend-display" class="legend" transform="translate({concat($full-width + 12.8 - $titleW - $w,' ',$y)})" opacity="0.8">
       
   250 	  	<g id="legend-owner">
       
   251 			<rect id="legend-ctrl" rx="{$legendDx}" ry="{$legendDx}" height="{$h}" width="{$w +  $legendDx}" x="0" y="0" visibility="hidden" pointer-events="all"/>
       
   252 	    </g>
       
   253 	</g>	
       
   254 </xsl:template>
       
   255 
       
   256 
       
   257 <xsl:template match="@copyright | @distribution | @revision-type">
       
   258 	<xsl:apply-templates select="." mode="as-text"/>
       
   259 </xsl:template>
       
   260 
       
   261 
       
   262 <xsl:template match="node()" mode="as-text" priority="-1"><xsl:value-of select="."/></xsl:template>
       
   263 <xsl:template match="@copyright" mode="as-text">Copyright &#xa9; <xsl:value-of select="."/></xsl:template>
       
   264 
       
   265 <xsl:template match="@distribution" mode="as-text">
       
   266 	<xsl:choose>
       
   267 		<xsl:when test=".='secret'">SECRET</xsl:when>
       
   268 		<xsl:when test=".='confidential'">CONFIDENTIAL</xsl:when>
       
   269 		<xsl:when test=".='internal'">INTERNAL</xsl:when>
       
   270 		<xsl:when test=".='unrestricted'">UNRESTRICTED</xsl:when>
       
   271 		<xsl:otherwise><xsl:value-of select="."/><xsl:message>
       
   272 Warning: unknown security classification: <xsl:value-of select="."/></xsl:message></xsl:otherwise>
       
   273 	</xsl:choose>
       
   274 </xsl:template>
       
   275 
       
   276 
       
   277 <xsl:template match="@revision-type" mode="as-text">
       
   278 	<xsl:choose> <!-- known values are in uppercase -->
       
   279 		<xsl:when test=".='draft'">DRAFT</xsl:when>
       
   280 		<xsl:when test=".='issued'">ISSUED</xsl:when>
       
   281 		<xsl:when test=".='build'">Build</xsl:when>
       
   282 		<xsl:when test=".='date' and ../@revision!=''"/> <!-- don't show word 'date', just show the date -->
       
   283 		<xsl:otherwise><xsl:value-of select="normalize-space(.)"/></xsl:otherwise>
       
   284 	</xsl:choose>
       
   285 </xsl:template>
       
   286 
       
   287 <xsl:template match="@label"><xsl:param name="h"/>
       
   288 	<text text-anchor="start" class="lgd" dominant-baseline="mathematical" x="0">
       
   289 		<xsl:attribute name="y"><xsl:value-of select="$h div 2 "/></xsl:attribute>
       
   290 		<xsl:for-each select=".."><xsl:call-template name="display-name"/></xsl:for-each>
       
   291 	</text>
       
   292 </xsl:template>
       
   293 
       
   294 <xsl:template match="note"><xsl:param name="h"/>
       
   295 	<xsl:variable name="off"><xsl:apply-templates select="." mode="offset"/></xsl:variable>
       
   296 	<xsl:variable name="w"><xsl:apply-templates select="." mode="width"/></xsl:variable>
       
   297 
       
   298 	<xsl:variable name="newlines" select="string-length(.) - string-length(translate(.,'&#xa;',''))"/>	
       
   299 	<text text-anchor="middle"  class="label"  dominant-baseline="mathematical" x="{$off + 0.5* $w}" y="{$h div 2}">
       
   300 		<xsl:copy-of select="@style|@class"/>
       
   301 		<xsl:call-template name="multiline">
       
   302 			<xsl:with-param name="x" select="$off  + 0.5* $w"/>
       
   303 			<xsl:with-param name="n" select="-0.5 * $newlines"/>
       
   304 			<xsl:with-param name="t">
       
   305 				<xsl:apply-templates select="." mode="eval-label"/>
       
   306 			</xsl:with-param>
       
   307 		</xsl:call-template>			
       
   308 	</text>
       
   309 </xsl:template>
       
   310 
       
   311 <xsl:template name="title-line1"> <!--  must call on systemModel element-->
       
   312 	<xsl:value-of select="@name"/>
       
   313 	<xsl:if test="@ver"><xsl:value-of select="concat(' v',@ver)"/></xsl:if>
       
   314 </xsl:template>
       
   315 
       
   316 <xsl:template name="title-line2"> <!--  must call on systemModel element-->
       
   317 	<xsl:if test="@label"><xsl:value-of select="@label"/></xsl:if>
       
   318 		<!-- type is deprecated -->
       
   319 	<xsl:if test="@type">
       
   320 		<xsl:value-of select="concat(@type,' Model')"/>
       
   321 		<xsl:call-template name="Caller-Warning"><xsl:with-param name="text">systemModel attribute "type" is deprecated, use "label" instead</xsl:with-param></xsl:call-template>
       
   322 	</xsl:if>
       
   323 </xsl:template>
       
   324 
       
   325 
       
   326 <xsl:template name="title-line3"> <!--  must call on systemModel element-->
       
   327 	<xsl:choose> <!-- show nothing if nothing specified, but leave tspan in case later need for it -->
       
   328 		<xsl:when test="@revision">
       
   329 			<xsl:variable name="rt"><xsl:apply-templates select="@revision-type"/></xsl:variable>
       
   330 			<xsl:if test="$rt!=''">	<!--  space follows if not empty -->
       
   331 				<xsl:value-of select="concat($rt,' ')"/>							
       
   332 			</xsl:if>
       
   333 			<xsl:value-of select="@revision"/>
       
   334 		</xsl:when>
       
   335 		<xsl:when test="@revision-type">
       
   336 				<xsl:apply-templates select="@revision-type"/>
       
   337 			</xsl:when>					
       
   338 		<!-- The following are deprecated -->
       
   339 		<xsl:when test="@draft">
       
   340 			<xsl:message>Warning: deprecated syntax draft="<xsl:value-of select="@draft"/>" </xsl:message>
       
   341 			<xsl:value-of select="concat('DRAFT ',@draft)"/>
       
   342 		</xsl:when>
       
   343 		<xsl:when test="@issued">
       
   344 			<xsl:message>Warning: deprecated syntax issued="<xsl:value-of select="@issued"/>" </xsl:message>
       
   345 			<xsl:value-of select="concat('ISSUED ',@issued)"/>
       
   346 		</xsl:when>
       
   347 	</xsl:choose>
       
   348 </xsl:template>
       
   349 
       
   350 <xsl:template match="systemModel" mode="legend-title-width">
       
   351 	<xsl:variable name="titleW" select="72.8"/> <!--  min title width -->
       
   352 	<xsl:variable name="len">
       
   353 		<xsl:call-template name="multiline-width">
       
   354 			<xsl:with-param name="t">	
       
   355 				<xsl:call-template name="title-line1"/>
       
   356 				<xsl:text>&#xa;</xsl:text>
       
   357 				<xsl:call-template name="title-line2"/>
       
   358 				<xsl:text>&#xa;</xsl:text>
       
   359 				<xsl:call-template name="title-line3"/>
       
   360 			</xsl:with-param>
       
   361 		</xsl:call-template>
       
   362 	</xsl:variable>
       
   363 	
       
   364 	<xsl:variable name="h"><xsl:call-template name="title-line-height"/></xsl:variable>
       
   365 		<!--  the width is a guess based on 2/3 of the (expected) bold font size -->
       
   366 	<xsl:choose>
       
   367 		<!-- use min width only if title is not explicitly scaled -->
       
   368 		<xsl:when test="(5 + $len * 0.66 * $h &lt; $titleW) and not(legend-layer/@title-scale)"><xsl:value-of select="$titleW"/></xsl:when>
       
   369 		<xsl:otherwise><xsl:value-of select="5 + $len * 0.66 * $h"/></xsl:otherwise>
       
   370 	</xsl:choose>
       
   371 </xsl:template>
       
   372 
       
   373 <xsl:template match="systemModel" mode="legend-label">
       
   374 	<xsl:param name="x"/>
       
   375 	<xsl:param name="y"/>
       
   376 	<text  text-anchor="middle" class="title" x="{$x}" y="{$y}">
       
   377 		<xsl:call-template name="title-line1"/>
       
   378 		<tspan dy="1em" x="{$x}">
       
   379 			<xsl:call-template name="title-line2"/>
       
   380 		</tspan>
       
   381 		<tspan font-style="italic" dy="1em" id="release-version" x="{$x}">
       
   382 			<!-- show nothing if nothing specified, but leave tspan in case later need for it -->
       
   383 			<xsl:variable name="t3"><xsl:call-template name="title-line3"/></xsl:variable>
       
   384 			<xsl:if test="@revision and starts-with($t3,'DRAFT') or @draft or (@revision-type and not(@revision))">
       
   385 				<!-- draft is in uppercase, but not bold font -->
       
   386 				<!-- or if it's just the type with no value, put in non-bold font. -->
       
   387 					<xsl:attribute name="font-weight">normal</xsl:attribute>
       
   388 			</xsl:if>
       
   389 			<xsl:value-of select="$t3"/>	
       
   390 		</tspan>
       
   391 	</text>
       
   392 </xsl:template>
       
   393 
       
   394 <xsl:template match="legend"><xsl:param name="h"/>
       
   395 	<xsl:variable name="name"><xsl:call-template name="name-value"/></xsl:variable>
       
   396 	<xsl:variable name="off"><xsl:apply-templates select="." mode="offset"/></xsl:variable>
       
   397 	<xsl:if test="$name!=''">
       
   398 		<text text-anchor="middle"  class="label"  dominant-baseline="mathematical" x="{$off + 3.5}" y="{$h div 2}">
       
   399 			<xsl:attribute name="width">10</xsl:attribute>
       
   400 			<xsl:if test="@font"><xsl:attribute name="style">font-family: '<xsl:value-of select="@font"/>'</xsl:attribute></xsl:if>	
       
   401 			<xsl:value-of select="$name"/>:</text>
       
   402 	</xsl:if>
       
   403 	<xsl:variable name="dx"><xsl:choose><xsl:when test="$name=''">0</xsl:when><xsl:otherwise>10</xsl:otherwise></xsl:choose></xsl:variable>
       
   404 	<g>
       
   405 		<xsl:attribute name="transform">translate(<xsl:value-of select="concat($off + $dx,' 0')"/>)</xsl:attribute>
       
   406 		<xsl:choose>
       
   407 			<xsl:when test="@sort='yes'">
       
   408 				<xsl:apply-templates select="*| key('ldg-use',@use)/*[@lookup or @label]">
       
   409 					<xsl:sort select="concat(@label,@lookup)"/>
       
   410 					<xsl:with-param name="h" select="$h"/>		<!-- available height  -->	
       
   411 					<xsl:with-param name="y" select="0"/>				<!-- vertical offset  -->	
       
   412 					<xsl:with-param name="spacing" select="$legendDx"/>		<!-- space between items (if necessary) -->	
       
   413 				</xsl:apply-templates>	
       
   414 			</xsl:when>
       
   415 			<xsl:otherwise>
       
   416 				<xsl:apply-templates select="*| key('ldg-use',@use)/*[@lookup or @label]">
       
   417 					<xsl:with-param name="h" select="$h"/>		<!-- available height  -->	
       
   418 					<xsl:with-param name="y" select="0"/>				<!-- vertical offset  -->	
       
   419 					<xsl:with-param name="spacing" select="$legendDx"/>		<!-- space between items (if necessary) -->	
       
   420 				</xsl:apply-templates>			
       
   421 			</xsl:otherwise>
       
   422 		</xsl:choose>
       
   423 	</g>
       
   424 </xsl:template>
       
   425 
       
   426 <xsl:template match="cmp|cbox|legend|note|group|legend-layer" mode="name">
       
   427 	<xsl:choose>
       
   428 		<xsl:when test="@label-ref"><xsl:apply-templates mode="eval-label" select="."/></xsl:when> <!-- evaluated name -->
       
   429 		<xsl:when test="@abbrev"><xsl:value-of select="@abbrev"/></xsl:when> <!-- localisation override-->
       
   430 		<xsl:when test="@label"><xsl:value-of select="@label"/></xsl:when> <!-- label override-->
       
   431 		<xsl:when test="self::legend[@use]"><xsl:apply-templates select="key('ldg-use',@use)" mode="name"/></xsl:when> <!-- for legends -->
       
   432 		<xsl:when test="name"><xsl:value-of select="name"/></xsl:when>
       
   433 		<xsl:when test="@lookup"><xsl:value-of select="@lookup"/></xsl:when>
       
   434 		<xsl:when test="@name"><xsl:value-of select="@name"/></xsl:when>
       
   435 		<xsl:when test="self::cmp"><xsl:value-of select="text()"/></xsl:when>
       
   436 	</xsl:choose>
       
   437 </xsl:template>
       
   438 
       
   439 <xsl:template match="group[@type='border']/cmp[@value]" mode="shape">
       
   440 	<xsl:value-of select="@value"/>
       
   441 </xsl:template>
       
   442 
       
   443 <xsl:template match="group[@type='overlay']/cmp[@value]" mode="overlay-style">
       
   444 	<xsl:text>fill: url(</xsl:text>
       
   445 	<xsl:value-of select="@value"/>
       
   446 	<xsl:text>); stroke: none; stroke-width: 0;</xsl:text>
       
   447 </xsl:template>
       
   448 
       
   449 <xsl:template match="group[@type='style']/cmp[@value]" mode="display-style-aux" priority="6">
       
   450 	<xsl:value-of select="@value"/>;</xsl:template>
       
   451 
       
   452 <xsl:template match="group[@type='text-highlight']/cmp[@value]" mode="text-filter"  priority="8">
       
   453 		<xsl:attribute name="filter">url(<xsl:value-of select="@value"/>)</xsl:attribute>
       
   454 </xsl:template>
       
   455 
       
   456 <xsl:template match="group[@type='highlight']/cmp[@value]" mode="filter" priority="8">
       
   457 	<xsl:attribute name="filter">url(<xsl:value-of select="@value"/>)</xsl:attribute>
       
   458 </xsl:template>
       
   459 
       
   460 
       
   461 <xsl:template match="note[not(@label-ref)]" mode="eval-label" priority="5"><xsl:value-of select="."/></xsl:template>
       
   462 <xsl:template match="legend[not(@label-ref)]" mode="eval-label" priority="5"><xsl:value-of select="@label"/></xsl:template>
       
   463 <xsl:template match="cmp|cbox" mode="eval-label" priority="-3"><xsl:value-of select="@label"/></xsl:template>
       
   464 <xsl:template match="cmp[not(@label)] | note" mode="eval-label" priority="-2"><xsl:value-of select="."/></xsl:template>
       
   465 
       
   466 <xsl:template match="legend[not(*) and not(@use)]" mode="width" priority="1">
       
   467 		<xsl:variable name="len">
       
   468 			<xsl:call-template name="multiline-width">
       
   469 			<xsl:with-param name="t"><xsl:call-template name="name-value"/></xsl:with-param>
       
   470 		</xsl:call-template>
       
   471 	</xsl:variable>
       
   472 
       
   473 	<!--  the width is a guess based on the half the (expected) font size of 4.233 + a border of 2.5 on each side-->
       
   474 		<xsl:value-of select="5 + $len * 0.5 * 1.94"/>
       
   475 </xsl:template>
       
   476 
       
   477 <xsl:template name="multiline"><xsl:param name="x" select="0"/><xsl:param name="n" select="1"/><xsl:param name="t" select="."/>
       
   478 <xsl:choose>
       
   479 	<xsl:when test="contains($t,'&#xa;')">
       
   480 		<tspan dy="{$n}em" x="{$x}">
       
   481 		<xsl:value-of select="normalize-space(substring-before($t,'&#xa;'))"/></tspan>	
       
   482 		<xsl:call-template name="multiline">
       
   483 			<xsl:with-param name="x" select="$x"/>
       
   484 			<xsl:with-param name="t" select="substring-after($t,'&#xa;')"/>
       
   485 		</xsl:call-template>
       
   486 	</xsl:when>
       
   487 	<xsl:otherwise>
       
   488 		<tspan dy="{$n}em" x="{$x}"><xsl:value-of select="normalize-space($t)"/></tspan>	
       
   489 	</xsl:otherwise>
       
   490 </xsl:choose>
       
   491 </xsl:template>
       
   492 
       
   493 <xsl:template name="multiline-width"><xsl:param name="t" select="."/>
       
   494 	<xsl:choose>
       
   495 		<xsl:when test="contains($t,'&#xa;')">
       
   496 			<xsl:variable name="len" select="string-length(normalize-space(substring-before($t,'&#xa;')))"/>
       
   497 			<xsl:variable name="next">
       
   498 				<xsl:call-template name="multiline-width">
       
   499 					<xsl:with-param name="t" select="substring-after($t,'&#xa;')"/>
       
   500 				</xsl:call-template>
       
   501 			</xsl:variable>
       
   502 		<xsl:choose>
       
   503 			<xsl:when test="$len &lt; $next"><xsl:value-of select="$next"/></xsl:when>
       
   504 			<xsl:otherwise><xsl:value-of select="$len"/></xsl:otherwise>
       
   505 		</xsl:choose>
       
   506 		</xsl:when>
       
   507 		<xsl:otherwise><xsl:value-of select="string-length(normalize-space($t))"/></xsl:otherwise>
       
   508 	</xsl:choose>
       
   509 </xsl:template>
       
   510 
       
   511 
       
   512 <!-- undocumented feature: allowing multiple lines by using newlines in label attribute. Might want to remove or make available to all labels -->
       
   513 <xsl:template match="legend[not(*) and not(@use)]" priority="1"><xsl:param name="h"/>
       
   514 	<xsl:variable name="name"><xsl:call-template name="name-value"/></xsl:variable>
       
   515 	<xsl:variable name="off"><xsl:apply-templates select="." mode="offset"/></xsl:variable>
       
   516 	<xsl:variable name="width"><xsl:apply-templates select="." mode="width"/></xsl:variable>
       
   517 	<xsl:variable name="newlines" select="string-length($name) - string-length(translate($name,'&#xa;',''))"/>
       
   518 
       
   519 	<xsl:if test="$name!=''">
       
   520 		<text text-anchor="middle"  class="label"  dominant-baseline="mathematical" x="{$off + 0.5 * $width}" y="{$h div 2}">
       
   521 		<xsl:call-template name="multiline">
       
   522 			<xsl:with-param name="x" select="$off + 0.5 * $width"/>
       
   523 			<xsl:with-param name="n" select="-0.5 * $newlines"/>
       
   524 			<xsl:with-param name="t" select="$name"/>
       
   525 		</xsl:call-template>
       
   526 		</text>
       
   527 	</xsl:if>
       
   528 </xsl:template>
       
   529 
       
   530 
       
   531 <xsl:template match="*" mode="show-unused-colorsbackground"/>
       
   532 <xsl:template match="*" mode="show-unused-colorshighlight"/>
       
   533 <xsl:template match="*" mode="show-unused-colorstext-highlight"/>
       
   534 <xsl:template match="*" mode="show-unused-patterns"/>
       
   535 <xsl:template match="*" mode="show-unused-borders"/>
       
   536 <xsl:template match="*" mode="show-unused-styles"/>
       
   537 
       
   538 <!--  should only be used in case exslt is not available 
       
   539 <xsl:template match="legend[@use]" mode="width" priority="7">
       
   540 	<xsl:apply-templates select="key('ldg-use',@use)" mode="width"/>
       
   541 </xsl:template>-->
       
   542 
       
   543 <xsl:template match="legend" mode="content-width" priority="-1"/>
       
   544 <xsl:template match="*[cbox]" mode="content-width"><xsl:param name="h"/><xsl:param name="dx"/>
       
   545 	<xsl:value-of select="$cboxWidth * (ceiling(   count(cbox[@label|@lookup])  div floor(($h - $legendDx) div $cboxHeight)) )+ $dx"/>
       
   546 </xsl:template>
       
   547 
       
   548 <xsl:template match="legend[cmp|legend] | group[cmp]" mode="content-width"><xsl:param name="dx"/>
       
   549 	<xsl:call-template name="sum-list">
       
   550 		<xsl:with-param name="list">
       
   551 			<xsl:value-of select="concat($dx - $legendDx,' ',   count(cmp[@label|@lookup or (parent::legend and text())]) * ($cSize + $legendDx),' ')"/>
       
   552 			<xsl:for-each select="legend">
       
   553 				<xsl:apply-templates select="." mode="width"/><xsl:value-of select="concat(' ',$legendDx,' ')"/>
       
   554 			</xsl:for-each>
       
   555 		</xsl:with-param> 
       
   556 	</xsl:call-template>
       
   557 </xsl:template>
       
   558 
       
   559 <xsl:template match="legend" mode="width">
       
   560 	<xsl:variable name="h"><xsl:apply-templates select="ancestor::legend-layer" mode="content-height"/></xsl:variable>
       
   561 	<xsl:variable name="name"><xsl:call-template name="name-value"/></xsl:variable>
       
   562 	<xsl:variable name="dx"><xsl:choose><xsl:when test="$name=''">0</xsl:when><xsl:otherwise>10</xsl:otherwise></xsl:choose></xsl:variable>
       
   563 	<xsl:choose> <!-- for compat with not exslt processors -->
       
   564 		<xsl:when test="@use">
       
   565 			<xsl:apply-templates select="key('ldg-use',@use)" mode="content-width">
       
   566 				<xsl:with-param name="dx" select="$dx"/>
       
   567 				<xsl:with-param name="h" select="$h"/>
       
   568 			</xsl:apply-templates>
       
   569 		</xsl:when>
       
   570 		<xsl:when test="*">
       
   571 			<xsl:apply-templates select="." mode="content-width">
       
   572 				<xsl:with-param name="dx" select="$dx"/>
       
   573 				<xsl:with-param name="h" select="$h"/>
       
   574 			</xsl:apply-templates>
       
   575 		</xsl:when>
       
   576 		<xsl:otherwise>0</xsl:otherwise>
       
   577 	</xsl:choose>
       
   578 </xsl:template>
       
   579 
       
   580 <!--  calc smallest height any legend item can use -->
       
   581 
       
   582 <xsl:template match="legend[legend]" mode="min-height">
       
   583 	<xsl:call-template name="max-from-list">
       
   584 		<xsl:with-param name="list">
       
   585 			<xsl:for-each select="legend"><xsl:apply-templates select="." mode="min-height"/><xsl:text>  </xsl:text></xsl:for-each>
       
   586 		</xsl:with-param>
       
   587 	</xsl:call-template>
       
   588 </xsl:template>
       
   589 
       
   590 <xsl:template match="legend[@use]" mode="min-height">
       
   591 	<xsl:apply-templates select="key('ldg-use',@use)"  mode="min-height"/>
       
   592 </xsl:template>
       
   593 
       
   594 <xsl:template match="legend[cbox] | group[cbox]" mode="min-height">
       
   595 <!-- the smallest this can be is the height of a cbox
       
   596 	However, if there are so many that it's wider than 2/3 of the model (to leave some room for the title, etc), then 
       
   597 	figure out how many tall these need to be in order to fit. Can't be less than one tall.
       
   598 	The 1.01 factor is to avoid rounding errors
       
   599 	This really should be calculated more exactly
       
   600 	-->
       
   601 	<xsl:value-of select="$cboxHeight * ceiling($cboxWidth * count(cbox) div  ($full-width * 0.5)) * 1.01"/>
       
   602 </xsl:template>
       
   603 
       
   604 <xsl:template match="legend[component|cmp] | group[component|cmp]" mode="min-height"><xsl:value-of select="$cSize"/></xsl:template>
       
   605 <xsl:template match="note" mode="min-height">3.1</xsl:template>
       
   606 <xsl:template match="legend[legend]" mode="min-height">
       
   607 	<xsl:call-template name="max-from-list">
       
   608 		<xsl:with-param name="list">
       
   609 			<xsl:value-of select="concat($cSize,' ')"/>
       
   610 			<xsl:for-each select="*"><xsl:apply-templates select="." mode="min-height"/><xsl:text>  </xsl:text>	</xsl:for-each>
       
   611 		</xsl:with-param>
       
   612 	</xsl:call-template>
       
   613 
       
   614 </xsl:template>
       
   615 
       
   616 	<!-- end calc height -->
       
   617 
       
   618 
       
   619 
       
   620 
       
   621 <xsl:template match="*" mode="color"><xsl:attribute name="fill"><xsl:value-of select="@color"/></xsl:attribute></xsl:template>
       
   622 <xsl:template match="cbox" mode="color"><xsl:attribute name="fill"><xsl:value-of select="@value"/></xsl:attribute></xsl:template>
       
   623 
       
   624 <xsl:template match="legend/cbox|group/cbox"><xsl:param name="h"/><!-- can only have one type per legend -->
       
   625 	<xsl:variable name="rows" select="floor($h div $cboxHeight)"/>
       
   626 	<xsl:variable name="total" select="count(../cbox[@label|@lookup])"/>
       
   627 	<xsl:variable name="cols" select="ceiling($total div $rows)"/>
       
   628 	<xsl:variable name="dy" select="($h -  floor(1 + ($total - 1) div $cols) * $cboxHeight)  div 2"/>
       
   629 	<xsl:variable name="index" select="position() - 1"/>
       
   630 
       
   631 		<g id="{@id|@style-id}">
       
   632 			<!-- id used for mouseover animations -->
       
   633 			<rect  class="cbox" height="{$cboxHeight}" width="{$cboxWidth}">
       
   634 				<xsl:apply-templates select="." mode="color"/>
       
   635 				<xsl:attribute name="x"><xsl:value-of select="$cboxWidth * ($index mod $cols)"/></xsl:attribute>
       
   636 				<xsl:attribute name="y"><xsl:value-of select="$dy + floor($index div $cols) * $cboxHeight"/></xsl:attribute>
       
   637 			</rect>
       
   638 			<text  text-anchor="middle" class="cbox" width="{$cboxWidth}" dominant-baseline="mathematical">
       
   639 				<xsl:attribute name="x"><xsl:value-of select="$cboxWidth * (($index mod $cols) + 0.5)"/></xsl:attribute>
       
   640 				<xsl:attribute name="y"><xsl:value-of select="$dy + ( 0.5 + floor($index div $cols)) * $cboxHeight"/></xsl:attribute>
       
   641 				<xsl:if test="@font"><xsl:attribute name="style">font-family: '<xsl:value-of select="@font"/>'</xsl:attribute></xsl:if>				
       
   642 				<xsl:apply-templates mode="name" select="."/>
       
   643 			</text>
       
   644 		</g>
       
   645 </xsl:template>
       
   646 
       
   647 <xsl:template match="cbox" mode="id">color-<xsl:value-of select="concat(name(),'-',count(preceding::cbox))"/></xsl:template>
       
   648 <xsl:template match="cmp" mode="id">style-<xsl:value-of select="concat(name(),'-',count(preceding::cmp))"/></xsl:template>
       
   649 <xsl:template match="*[@style-id]" mode="id"><xsl:value-of select="concat(name(),'-',@style-id)"/></xsl:template>
       
   650 
       
   651 <xsl:template match="legend[s:g]" mode="width"><xsl:value-of select="sum(s:g/@width)"/></xsl:template>
       
   652 <xsl:template match="legend[s:g]" mode="min-height"><xsl:value-of select="s:g/@height"/></xsl:template>
       
   653 <xsl:template match="legend/s:g">
       
   654 	<xsl:copy-of select="."/>
       
   655 </xsl:template>
       
   656 
       
   657 
       
   658 <!-- replace temporary legend items' labels with evaluated ones-->
       
   659 <xsl:template match="legend|cbox|cmp|group|legend-layer" mode="make-label">
       
   660 	<xsl:copy-of select="@font"/>
       
   661 	<xsl:choose>
       
   662 		<xsl:when test="@label-ref"><xsl:attribute name="label"><xsl:apply-templates mode="eval-label" select="."/></xsl:attribute></xsl:when>
       
   663 		<xsl:when test="@label"><xsl:copy-of select="@label"/></xsl:when>
       
   664 		<xsl:when test="@lookup"><xsl:attribute name="label"><xsl:value-of select="@lookup"/></xsl:attribute></xsl:when>
       
   665 		<xsl:when test="self::cmp[text()]"><xsl:attribute name="label"><xsl:value-of select="."/></xsl:attribute></xsl:when>
       
   666 	</xsl:choose>
       
   667 </xsl:template>
       
   668 
       
   669 <xsl:template match="note" mode="make-label">
       
   670 	<xsl:choose>
       
   671 		<xsl:when test="not(@label-ref)"><xsl:copy-of select="node()"/></xsl:when>
       
   672 		<xsl:otherwise><xsl:apply-templates mode="eval-label" select="."/></xsl:otherwise>
       
   673 	</xsl:choose>
       
   674 </xsl:template>
       
   675 
       
   676 
       
   677 
       
   678 <!-- determine if generated stuff is present or not -->
       
   679 
       
   680 <xsl:template match="node()" mode="legend-copy" priority="-2">
       
   681 	<xsl:copy><xsl:copy-of select="@*"/>
       
   682 		<xsl:apply-templates  mode="legend-copy"/>
       
   683 	</xsl:copy>
       
   684 </xsl:template>
       
   685 
       
   686 <xsl:template match="layer" mode="legend-copy" priority="-1">
       
   687 	<xsl:copy-of select="."/>
       
   688 </xsl:template>
       
   689 
       
   690 <xsl:template match="legend-layer" mode="legend-copy">
       
   691 	<xsl:choose>
       
   692 		<xsl:when test="not(function-available('exslt:node-set'))"/>
       
   693 		<xsl:otherwise>
       
   694 			<xsl:copy><xsl:copy-of select="@*[name()!='label' and name()!='literal' and name()!='label-ref']"/>
       
   695 				<xsl:if test="@label"><xsl:apply-templates select="." mode="make-label"/></xsl:if>
       
   696 				<xsl:apply-templates  mode="legend-copy"/>
       
   697 			</xsl:copy>
       
   698 		</xsl:otherwise>
       
   699 	</xsl:choose>
       
   700 </xsl:template>
       
   701 
       
   702 <xsl:template match="legend/@use" mode="legend-copy">
       
   703 	<xsl:apply-templates select="key('ldg-use',.)/*" mode="legend-copy">
       
   704 		<xsl:with-param name="show-unused" select="../@show-unused"/>
       
   705 	</xsl:apply-templates>
       
   706 </xsl:template>
       
   707 
       
   708 <xsl:template match="legend" mode="legend-copy">
       
   709 	<xsl:variable name="content">
       
   710 		<xsl:apply-templates mode="legend-copy" select="* | @use"/>
       
   711 	</xsl:variable>
       
   712 	<xsl:if test="exslt:node-set($content)/descendant-or-self::*">
       
   713 		<!-- only show if all the content is present (do we really want to do this? It means the label won't show if nothing is present) -->
       
   714 		<xsl:copy><xsl:copy-of select="@*[name()!='label' and name()!='literal' and name()!='label-ref' and name()!='show-unused' and name()!='use' and name()!='type']"/>
       
   715 <!-- 		<xsl:copy-of select="key('ldg-use',@use)/@*[name()='type' or name()='style-id']"/>-->
       
   716 			<xsl:choose>
       
   717 				<xsl:when test="@label"><xsl:apply-templates select="." mode="make-label"/></xsl:when>
       
   718 				<xsl:otherwise><xsl:apply-templates select="key('ldg-use',@use)" mode="make-label"/></xsl:otherwise>
       
   719 			</xsl:choose>
       
   720 			<xsl:copy-of select="$content"/>
       
   721 		</xsl:copy>
       
   722 	</xsl:if>
       
   723 </xsl:template>
       
   724 
       
   725 <xsl:template match="legend[not(@use or *)]" mode="legend-copy" priority="2">
       
   726 	<xsl:copy><xsl:copy-of select="@*[name()!='label' and name()!='literal' and name()!='label-ref']"/>
       
   727 		<xsl:apply-templates select="." mode="make-label"/>
       
   728 		<xsl:apply-templates select="node()" mode="legend-copy"/>
       
   729 	</xsl:copy>
       
   730 </xsl:template>
       
   731 
       
   732 
       
   733 <xsl:template match="note[@label-ref]" mode="legend-copy">
       
   734 	<xsl:copy><xsl:copy-of select="@*[name()!='label' and name()!='literal' and name()!='label-ref']"/>
       
   735 		<xsl:apply-templates select="." mode="make-label"/>
       
   736 	</xsl:copy>
       
   737 </xsl:template>
       
   738 
       
   739 <xsl:template match="*" mode="is-showable" priority="-1"/>
       
   740 <xsl:template match="layer | *[$Detail=name() or not($Static or /SystemDefinition/systemModel/@detail-type='fixed')]" priority="4" mode="is-showable">1</xsl:template>
       
   741 <xsl:template match="collection[$Detail='component' or $Detail='module']" mode="is-showable">1</xsl:template>
       
   742 <xsl:template match="subblock[$Detail='component' or $Detail='module' or $Detail='collection']" mode="is-showable">1</xsl:template>
       
   743 <xsl:template match="block[$Detail!='layer']" mode="is-showable">1</xsl:template>
       
   744 
       
   745 <xsl:template match="cbox|cmp" mode="legend-copy"><xsl:param name="show-unused"/>
       
   746 	<xsl:variable name="show">
       
   747 		<xsl:choose>
       
   748 			<xsl:when test="self::cbox[@label='']"/> <!-- always leave out -->
       
   749 			<xsl:when test="(/SystemDefinition/systemModel/@detail-type='fixed' or $Static) and ((../@detail='component' and $Detail!='component') or  
       
   750 			(../@detail='collection' and ($Detail='layer' or contains($Detail, 'block'))) or 
       
   751 			(../@detail='subblock' and ($Detail='layer' or $Detail='block')) or (../@detail='block' and $Detail='layer'))"/> <!--  hide stuff outside level of detail -->
       
   752 			<xsl:when test="$show-unused='yes' or ../@show-unused='yes'">1</xsl:when>
       
   753 			<xsl:when test="key('style-ref',@style-id)">
       
   754 				<xsl:apply-templates select="key('style-ref',@style-id)" mode="is-showable"/>
       
   755 			</xsl:when><!-- see if it's referenced by anything -->
       
   756 			<xsl:when test="@lookup"> <!-- anything with lookup attribute can be done fast -->
       
   757 				<xsl:apply-templates select="key(concat('use-',../@style-id),@lookup)" mode="is-showable"/>
       
   758 			</xsl:when>
       
   759 			<xsl:when test="self::cmp[parent::legend]">1<!-- example: always use --></xsl:when>
       
   760 			<!-- everything else is a rule -->
       
   761 			<xsl:when test="self::cbox">
       
   762 				<xsl:apply-templates select="//component|//collection|//block|//subblock|//module|//logicalset|//logicalsubset|layer" mode="show-unused-colorsbackground">
       
   763 		<!--		<xsl:apply-templates select="//component" mode="show-unused-colorsbackground"> -->
       
   764 					<xsl:with-param name="n" select="@style-id"/>
       
   765 				</xsl:apply-templates>
       
   766 			</xsl:when>
       
   767 			<xsl:when test="self::cmp[../@type='overlay']">
       
   768 				<!--			<xsl:apply-templates select="//component|//collection|//block|//subblock|//module|//logicalset|//logicalsubset|layer" mode="...">-->
       
   769 				<xsl:apply-templates select="//component" mode="show-unused-patterns">
       
   770 					<xsl:with-param name="n" select="@style-id"/>
       
   771 				</xsl:apply-templates>
       
   772 			</xsl:when>
       
   773 			<xsl:when test="self::cmp[../@type='border']">
       
   774 				<!--			<xsl:apply-templates select="//component|//collection|//block|//subblock|//module|//logicalset|//logicalsubset|layer" mode="...">-->
       
   775 				<xsl:apply-templates select="//component" mode="show-unused-borders">
       
   776 					<xsl:with-param name="n" select="@style-id"/>
       
   777 				</xsl:apply-templates>
       
   778 			</xsl:when>
       
   779 			<xsl:when test="self::cmp[../@type='style']">
       
   780 				<xsl:apply-templates select="//component|//collection|//block|//subblock|//module|//logicalset|//logicalsubset|layer" mode="show-unused-styles">
       
   781 					<xsl:with-param name="n" select="@style-id"/>
       
   782 				</xsl:apply-templates>
       
   783 			</xsl:when>
       
   784 			<xsl:when test="self::cmp[../@type='highlight']">
       
   785 				<xsl:apply-templates select="//component|//collection|//block|//subblock|//module|//logicalset|//logicalsubset|layer" mode="show-unused-colorshighlight">
       
   786 					<xsl:with-param name="n" select="@style-id"/>
       
   787 				</xsl:apply-templates>
       
   788 			</xsl:when>
       
   789 			<xsl:when test="self::cmp[../@type='text-highlight']">
       
   790 				<xsl:apply-templates select="//component|//collection|//block|//subblock|//module|//logicalset|//logicalsubset|layer" mode="show-unused-colorstext-highlight">
       
   791 					<xsl:with-param name="n" select="@style-id"/>
       
   792 				</xsl:apply-templates>
       
   793 			</xsl:when>
       
   794 			<xsl:otherwise>			<xsl:message>[
       
   795 	
       
   796 	<xsl:value-of select="."/>
       
   797 	
       
   798 	
       
   799 	]</xsl:message>
       
   800 			</xsl:otherwise>
       
   801 		</xsl:choose>
       
   802 	</xsl:variable>
       
   803 	<xsl:choose>
       
   804 		<xsl:when test="(@label | @lookup) and $show!='' ">
       
   805 			<xsl:copy> <!-- in some cases this had a label, but otherwise use the lookup value as the label -->
       
   806 				<xsl:attribute name="id"><xsl:value-of select="@style-id"/></xsl:attribute>
       
   807 				<xsl:copy-of select="@font"/> <!-- if any: can only be set via abbrevs file (consider removing this option) -->
       
   808 				<xsl:apply-templates select="." mode="make-label"/>
       
   809 				<xsl:choose>
       
   810 					<xsl:when test="self::cbox"><xsl:copy-of select="@value"/></xsl:when>
       
   811 					<xsl:otherwise>
       
   812 						<xsl:attribute name="generated-{../@type}"><xsl:value-of select="@value"/></xsl:attribute>
       
   813 					</xsl:otherwise>
       
   814 				</xsl:choose>
       
   815 			</xsl:copy>
       
   816 		</xsl:when>
       
   817 		<xsl:when test="self::cmp[parent::legend] and normalize-space(text()!='')">
       
   818 			<xsl:copy> <!-- in some cases this had a label, but otherwise use the lookup value as the label -->
       
   819 				<xsl:copy-of select="@font"/> <!-- if any: can only be set via abbrevs file (consider removing this option) -->
       
   820 				<xsl:apply-templates select="." mode="make-label"/>			
       
   821 				<xsl:for-each select="@*[starts-with(name(),'generator')]">
       
   822 					<xsl:attribute name="generated{substring-after(name(),'generator')}">
       
   823 						<xsl:for-each select="key('styled',.)"><xsl:value-of select="@value | @default"/></xsl:for-each>							
       
   824 					</xsl:attribute>
       
   825 				</xsl:for-each>
       
   826 			</xsl:copy>
       
   827 		</xsl:when>
       
   828 	</xsl:choose>
       
   829 </xsl:template>
       
   830 
       
   831 
       
   832 
       
   833 <!-- 
       
   834 <xsl:template match="legend" mode="width" priority="-2">100</xsl:template>
       
   835 <xsl:template match="legend|note" mode="offset">
       
   836 <xsl:template match="legend"><xsl:param name="h"/>
       
   837 <xsl:template match="legend[legend]" mode="min-height">
       
   838 
       
   839  -->
       
   840 </xsl:stylesheet>
       
   841 
       
   842