sysmodellibs/sysmodelgen/core/draw.xsl
changeset 7 3c36c452f013
parent 6 5b32dc297d05
equal deleted inserted replaced
6:5b32dc297d05 7:3c36c452f013
       
     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" xmlns:m="http://exslt.org/math" exclude-result-prefixes="s m exslt" >
       
     3 	<xsl:output method="xml" cdata-section-elements="script s:script" indent="yes"/>
       
     4 	<xsl:param name="Run"/> 
       
     5 		<!-- Selects the run mode, by default it will draw the model from the given layout data. The output is an SVG diagram. 
       
     6 		There are two other options:
       
     7 				"calc" - Indicates that it should just do all 1st-pass calculations and generate a model with those embedded. The generated XML output is non-standard and has a fragile syntax that cannot be relied upon.
       
     8 				"draw" - Draw the model from a pre-caculated result. The output is an SVG diagram. This will fail if run on raw layout data.  
       
     9 			The run mode options are mostly useful for debugging, though they can also be used for drawing a model
       
    10 			in low-memory or very large model situations. In the normal mode, the 1st pass is saved in memory before drawing. 
       
    11 			Saving to disk instead could greatly reduce the run-time memory usage.	-->
       
    12 		
       
    13 	<xsl:param name="Use-as-name" select="'name'"/> <!-- The attribute to use as the item name. Falls back to 'name' -->
       
    14 	  <xsl:key name="lgrp-bottom" match="layer-group" use="@from"/>
       
    15 	  <xsl:key name="lgrp-top" match="layer-group" use="@to"/>
       
    16 
       
    17 
       
    18 	<xsl:variable name="large-width" select="500"/> <!-- cutoff width to be considered a wide model and thus need larger title size -->
       
    19 
       
    20 <xsl:variable name="Versions">
       
    21 	<xsl:choose>
       
    22 		<xsl:when test="/SystemDefinition/*/meta[@rel='version-list']">
       
    23 			<xsl:copy-of select="/SystemDefinition/*/meta[@rel='version-list']"/>
       
    24 		</xsl:when>
       
    25 		<xsl:otherwise>
       
    26 			<v>ER5</v><v>ER5U</v>
       
    27 			<v>6.0</v> <v>6.1</v> <v>6.2</v>
       
    28 			 <v>7.0</v> <v>7.0s</v>
       
    29 			 <v>8.0</v> <v>8.0a 8.0b</v><v>8.1 8.1a 8.1b</v>
       
    30 			 <v>9.0</v> <v>9.1</v> <v>9.2</v> <v>9.3</v> 
       
    31 			 <v>9.4 ^1</v><v>tb91 ^2</v> <v>tb92 9.5 ^3</v> <v>tb101 9.6 ^4</v> 
       
    32 			 <v>^5</v> <v>^6</v> <v>^7</v> <v>^8</v> <v>^9</v> <v>^10</v>
       
    33 			 <v>Future</v>
       
    34 		</xsl:otherwise>
       
    35 	</xsl:choose>
       
    36 </xsl:variable>
       
    37 
       
    38 <xsl:template match="/SystemDefinition" priority="2">
       
    39 	<!-- see above for Run usage -->
       
    40 	<xsl:choose>
       
    41 		<xsl:when test="$Run = 'calc' ">
       
    42 			<!-- just do 1st pass calculations like sizing and legend generation -->
       
    43 			<xsl:apply-templates select="." mode="sizing"/>
       
    44 		</xsl:when>
       
    45 		<xsl:when test="$Run = 'draw' ">
       
    46 			<!-- draw from pre-calculated data -->
       
    47 			<xsl:apply-templates select="." mode="draw"/>
       
    48 		</xsl:when>
       
    49 		<xsl:otherwise> <!-- the normal case, run w/1st pass for sizing, then draw --> 
       
    50 			<xsl:variable name="sysdef">
       
    51 				<xsl:apply-templates select="." mode="sizing"/>
       
    52 			</xsl:variable>
       
    53 			<xsl:apply-templates select="exslt:node-set($sysdef)/SystemDefinition" mode="draw"/>
       
    54 		</xsl:otherwise>		
       
    55 	</xsl:choose>
       
    56 </xsl:template>
       
    57 
       
    58 
       
    59 
       
    60 <xsl:template match="SystemDefinition" mode="draw">
       
    61 	<xsl:if test="@resolution"><xsl:processing-instruction name="AdobeSVGViewer">resolution="<xsl:value-of select="@resolution"/>"</xsl:processing-instruction></xsl:if>
       
    62 	<!-- groupDy padding around whole thing -->
       
    63 	<svg version="1.1" onload="wrapalltext()" viewBox="{-$groupDy} {-$groupDy} {@width + $groupDy} {@height  + 2* $groupDy}">
       
    64 		<xsl:attribute name="class">
       
    65 			<xsl:if test="not(@detail)">component</xsl:if>
       
    66 			<xsl:value-of select="@detail"/>
       
    67 			<xsl:if test="@detail-type">-<xsl:value-of select="@detail-type"/></xsl:if>
       
    68 		</xsl:attribute>
       
    69 		<xsl:copy-of select="@xml:lang"/> <!-- localized language -->
       
    70 		<xsl:if test="not(@static='true') and (@navctrl or */meta/legend/@float)">
       
    71 			<xsl:attribute name="onscroll">resized()</xsl:attribute>
       
    72 			<xsl:attribute name="onzoom">resized()</xsl:attribute>
       
    73 			<xsl:attribute name="onresize">resized()</xsl:attribute>
       
    74 		</xsl:if>		
       
    75 		<xsl:apply-templates select="." mode="title"/>
       
    76 
       
    77 	<defs>
       
    78 
       
    79     <style type="text/css">
       
    80     text.layer, text.package, text.collection, text.component,
       
    81     text.cbox, text.lgrp, text.label, text.lgd {
       
    82 		fill:black;
       
    83 		font-family: <xsl:call-template name="default-font"/>;
       
    84     }
       
    85     text.title {
       
    86 		fill:red;
       
    87 		font-weight: bold;
       
    88 		font-size: <xsl:call-template name="title-line-height"/>px;	
       
    89 		font-family: <xsl:call-template name="default-font"/>;
       
    90     }    
       
    91     text.component {		
       
    92 		font-size: 1.940px;  /*  5.5pt  */
       
    93 		font-weight: bold;
       
    94 	}
       
    95  	text.lgd, 
       
    96 	text.layer, text.package {
       
    97 		font-size: 4.233px;  /*  12pt  */
       
    98 		font-weight: bold;
       
    99 	}
       
   100 	text.label {		
       
   101 		font-size: 1.940px;  /*  5.5pt  */
       
   102 		font-weight: bold
       
   103 	}
       
   104 	 text.level {
       
   105 		font-style: italic;
       
   106 		fill: blue;
       
   107 	}
       
   108 	g.layer text.level {		
       
   109 		font-size: 7.055px;  /*  20pt  */
       
   110 		font-style: italic;
       
   111 		fill: red;
       
   112 	}
       
   113 	g.package text.level {		
       
   114 		font-size: 4.233px;  /*  12pt  */
       
   115 	}
       
   116 	g.nested text.level {		
       
   117 		font-size: 3.175px;  /*  8pt  */
       
   118 	}
       
   119 	
       
   120 	text.cbox {		
       
   121 		font-size: 1.411px;  /*  4pt  */
       
   122 		font-weight: bold
       
   123 	}
       
   124 	text.lgrp {
       
   125 		font-size: 12.699px;  /*  36pt  */
       
   126 		font-weight: normal;
       
   127 	}
       
   128 <!-- package font sizes: larger if there is no displayed children -->
       
   129 g.placeholder text.package,
       
   130 svg.package text.package,
       
   131 svg.package-fixed text.package {
       
   132 		font-size: 11.288px;  /*  32pt  */
       
   133 		font-weight: normal;
       
   134 	}
       
   135 
       
   136 
       
   137 <!-- subpackage font sizes -->
       
   138 	g.nested text.package {
       
   139 		font-size: 2.822px;  /*  8pt  */
       
   140 	}
       
   141 	
       
   142 	svg.collection g.nested text.package,
       
   143 	svg.collection-fixed g.nested text.package  {
       
   144 		font-size: 4.233px;  /*  12pt  */
       
   145 	}
       
   146 	
       
   147 	svg.package g.nested text.package,
       
   148 	svg.package-fixed g.nested text.package  {
       
   149 		font-size: 7.055px;  /*  20pt  */
       
   150 	}
       
   151 <!-- collection font sizes -->
       
   152 	text.collection {
       
   153 		font-size: 2.469px;  /*  7pt  */
       
   154 	}
       
   155 	
       
   156 	g.placeholder text.collection,
       
   157 	svg.collection text.collection,
       
   158 	svg.collection-fixed text.collection  {
       
   159 		font-size: 3.7035px;  /*  10.5pt  */
       
   160 	} 
       
   161 <!-- borders -->
       
   162 	/* thin border */
       
   163 	rect.legend, rect.collection, rect.cbox {
       
   164 		stroke-width: 0.0882px;  /*  0.25pt  */
       
   165 		stroke: black
       
   166 	}
       
   167 	/* thick border */
       
   168 	rect.layer, rect.package  {
       
   169 		stroke-width: 0.2469px;  /*  0.7pt  */
       
   170 		stroke: black
       
   171 	}
       
   172 	rect.layer {
       
   173 		fill: #e6e6e6
       
   174 	}
       
   175 	rect.package {
       
   176 		fill: #b3b3b3
       
   177 	}
       
   178 	g.nested rect.package {
       
   179 		fill: #e6e6e6
       
   180 	}
       
   181 	rect.collection {
       
   182 		fill: white
       
   183 	}
       
   184 	rect.legend {
       
   185 		fill: white
       
   186 	}
       
   187 	<!-- opera does not support <style media="print">, so must use @media instead -->
       
   188 	 @media print {
       
   189 		#Zoom {visibility: hidden}
       
   190 	  }
       
   191  </style>	
       
   192  		<xsl:apply-templates select="." mode="shapes"/>
       
   193  
       
   194 	</defs>
       
   195 
       
   196 <script type="text/ecmascript"> 
       
   197 <!-- for creating / finding elements by namespace -->
       
   198 var svgns="http://www.w3.org/2000/svg";
       
   199 
       
   200 <xsl:call-template name="script-wrapping"/>
       
   201 <xsl:call-template name="script-popups"/> <!-- dependencies use this and they override @static -->
       
   202 <xsl:if test="not(@static='true')">
       
   203 	<xsl:if test="@navctrl">
       
   204 		<xsl:call-template name="script-navcontrol"/>
       
   205 	</xsl:if>
       
   206 function resized()
       
   207 		{
       
   208 		var viewbox = document.documentElement.getAttribute("viewBox").split(' ');
       
   209  		var x = Number(viewbox[0]);
       
   210  		var y = Number(viewbox[1]);
       
   211  		var width = Number(viewbox[2]);
       
   212  		var height = Number(viewbox[3]);
       
   213  		if( window.innerWidth==0 || window.innerHeight ==0 || height ==0) {return}
       
   214  		var s = width  / window.innerWidth;
       
   215  		if ( width / height &lt; window.innerWidth / window.innerHeight)
       
   216  			{
       
   217 			s = height  / window.innerHeight;
       
   218 			width = window.innerWidth * s;
       
   219 			}
       
   220 		else	
       
   221 			{
       
   222  			height = window.innerHeight * s;
       
   223  			}
       
   224 <xsl:if test="@navctrl">
       
   225 		var e = document.getElementById('Zoom');
       
   226 		var trans = 'translate(';
       
   227 		trans+= x - 0.5* (width - viewbox[2]) + ( -document.rootElement.currentTranslate.x ) * s  / document.rootElement.currentScale ;
       
   228 		trans+=' ';
       
   229 		trans+= y - 0.5* (height - viewbox[3]) + ( -document.rootElement.currentTranslate.y ) * s  / document.rootElement.currentScale ;
       
   230 		trans+=') scale(';
       
   231 		trans+=  (height / window.innerHeight) *3.2 / document.rootElement.currentScale;
       
   232 		trans+=')';
       
   233 		e.setAttribute('transform',trans);
       
   234 </xsl:if>
       
   235 <xsl:if test="*/meta/legend/@float">
       
   236 		e = document.getElementById('legend-display');
       
   237 		var ctrl = document.getElementById('legend-ctrl');
       
   238 		var wBox = Number(ctrl.getAttribute('width'));
       
   239 		scale = (width / window.innerWidth)  * (window.innerWidth / ( wBox+3)) / document.rootElement.currentScale;
       
   240 		trans = 'translate(';
       
   241 		trans+= x + (1.5 *scale )  -0.5* (width - viewbox[2]) + ( -document.rootElement.currentTranslate.x ) * s  / document.rootElement.currentScale ;
       
   242 		trans+=' ';
       
   243 		trans+= y -(14.3 +0.3)* scale - 0.5* (height - viewbox[3] ) + ( -document.rootElement.currentTranslate.y ) * s  / document.rootElement.currentScale 
       
   244 		+ height   / document.rootElement.currentScale
       
   245 		trans+=') scale(';
       
   246 		trans+=  scale;
       
   247 		trans+=')';
       
   248 		e.setAttribute('transform',trans);</xsl:if>		
       
   249  		}
       
   250 	<xsl:if test="*/meta/legend/@float">
       
   251 		<xsl:call-template name="script-float-legend"/>
       
   252 	</xsl:if>
       
   253 </xsl:if>
       
   254 </script>
       
   255 	<xsl:variable name="model-bottom">
       
   256 		<!-- The y-location of the bottom of the model itself -->
       
   257 		<xsl:for-each select="*[1]"> <!-- should only be one child -->
       
   258 			<xsl:choose>
       
   259 				<xsl:when test="meta[@rel='model-logo']/@height and (meta[@rel='model-logo']/@height &gt;meta[@rel='model-legend']/@height or not(meta[@rel='model-legend']))">
       
   260 					<xsl:value-of select="../@height - sum (meta[@rel='model-footer' or @rel='model-logo']/@height) "/>
       
   261 				</xsl:when>
       
   262 				<xsl:otherwise>
       
   263 					<xsl:value-of select="../@height - sum (meta[@rel='model-footer' or @rel='model-legend']/@height) "/>
       
   264 				</xsl:otherwise>
       
   265 			</xsl:choose>
       
   266 		</xsl:for-each>
       
   267 	</xsl:variable>
       
   268 	
       
   269 	<!-- these meta go under the model -->
       
   270 	<xsl:apply-templates select="*/meta[not(starts-with(@rel,'model-'))]" mode="global"/>
       
   271 	  
       
   272 	<xsl:apply-templates select="*"/>
       
   273 	
       
   274 	<!-- do these meta last so that it could obscure the model if it needs to -->
       
   275 		
       
   276 	<xsl:apply-templates select="*/meta[starts-with(@rel,'model-')]" mode="global">
       
   277 		<xsl:sort select="@rel"/>
       
   278 		<xsl:with-param name="bottom" select="$model-bottom"/> 
       
   279 	</xsl:apply-templates>
       
   280 	<xsl:if test="not(@static='true') and @navctrl">
       
   281 		<xsl:call-template name="navctrl"/>
       
   282 	</xsl:if>
       
   283 <!--
       
   284 <rect x="0" y="0" width="{@width}" height="{@height}" fill="none" stroke="black" stroke-width="1"/>
       
   285 <rect x="{@padding-left}" y="0" width="{@model-width}" height="{@model-height}" fill="none" stroke="black" stroke-width="1"/>
       
   286 <xsl:for-each select="meta[@rel='model-footer']">
       
   287 	<rect x="0" y="{../@height - @height}" width="{../@width}" height="{@height}" fill="none" stroke="green" stroke-width="1"/>
       
   288 </xsl:for-each>
       
   289 <xsl:for-each select="meta[@rel='model-logo']">
       
   290 	<rect x="0" y="{$model-bottom}" width="{@width}" height="{@height}" fill="none" stroke="green" stroke-width="1"/>
       
   291 </xsl:for-each>
       
   292 <xsl:for-each select="meta[@rel='model-legend']">
       
   293 	<rect x="{../@width - legend/@title-width * @scaled}" y="{$model-bottom}" width="{legend/@title-width * @scaled }" height="{legend/@title-height * @scaled}" fill="none" stroke="green" stroke-width="1"/>
       
   294 </xsl:for-each>
       
   295 -->
       
   296 	<xsl:apply-templates mode="validate"/>
       
   297 </svg>
       
   298 </xsl:template>
       
   299 
       
   300 <xsl:template match="systemModel">
       
   301 	<xsl:apply-templates select="*"/>
       
   302 </xsl:template>
       
   303 
       
   304 
       
   305 <xsl:template match="*" mode="filter"/> <!-- filters for all items -->
       
   306 <xsl:template match="*" mode="text-filter"/> <!-- fitler for just text -->
       
   307 
       
   308 
       
   309 <!-- scripts -->
       
   310 <xsl:template name="script-popups">
       
   311 <!-- for pop-ups which can only appear one at a time. 
       
   312 In general, one would want to use 
       
   313 	onmouseover="on('blah') onmouseout="off('blah')"
       
   314 for stuff which appears and disappears based on the position of the mouse (like dependency arrows)
       
   315 
       
   316 for stuff which appears based on a mouseover or button press, but does not 
       
   317 disappear until some other trigger (and only one can appear at a time), use one of:
       
   318 	onmouseover="on(clear('blah'))"
       
   319 	onclick="on(clear('blah'))"
       
   320 -->
       
   321 var curId = '';
       
   322 function clear(id) {
       
   323 	if(curId != '') off(curId);
       
   324 	return curId=id;
       
   325 }
       
   326 
       
   327 <!--  for showing and hiding : 
       
   328 	not used by default, but used by higher-detailed versions when Static is not set
       
   329 	also used by post-processed versions for showing pop-up data.-->
       
   330 function on(id) {
       
   331 	var cur =document.getElementById(id)
       
   332 	cur.setAttribute('visibility','visible');
       
   333 	<xsl:if test="not(@detail='component')"><!-- this is needed to wrap text which is initially hidden -->
       
   334 	if(!cur.hasAttribute('wrapenated')) {
       
   335 		cur.setAttribute('wrapenated','true');
       
   336 		wrapalltext(cur)
       
   337 	}
       
   338 	</xsl:if>
       
   339 	return cur;
       
   340 }
       
   341 
       
   342 function off(id) {
       
   343 	document.getElementById(id).setAttribute('visibility','hidden');
       
   344 }
       
   345 </xsl:template>
       
   346 
       
   347 
       
   348 <xsl:template name="script-wrapping">
       
   349 <!--  for wrapping: breaks text up into an array of words -->
       
   350 function splitup(txt) {
       
   351 	var a = new Array;
       
   352 	var t = txt;
       
   353 	var found		<!-- \u4e00-\ufa2 is the unicode range for kanjii, \u3041-\u309 is katakana and e\u30a1-\u30fe is hiragana-->
       
   354 	while((found = t.match(/(^[\u3041-\u309e\u30a1-\u30fe\u4e00-\ufa2d])([\u3041-\u309e\u30a1-\u30fe\u4e00-\ufa2d].*)$/))|| ( found = t.match(/^([^ \u200b\xad-]+[ \u200b\xad-]+)(.*)$/))) {
       
   355 			a.push(found[1]);
       
   356 			t=found[2];
       
   357 	}
       
   358 	a.push(t);
       
   359 	return a;
       
   360 }
       
   361 <!--  the remainder of the scripts also are for wrapping 
       
   362 
       
   363 Note that comments are kept to an absolute minimum inline since it's a waste of 
       
   364 	space in the generated file to duplicate the unused text 
       
   365 -->
       
   366 <![CDATA[
       
   367 function splitable(node) {
       
   368  	return node.firstChild.nodeType == 3 && node.firstChild.data.match(/[\t\n\r \u200b\xad-]/);
       
   369 }
       
   370 
       
   371 function crush(node, len) {
       
   372 	node.setAttribute('letter-spacing','-0.075em');
       
   373 	if( node.getComputedTextLength() > len) 
       
   374 		node.setAttribute('letter-spacing','-0.15em');
       
   375 }
       
   376 
       
   377 function whatSize(txt) { // convert a length into pixels
       
   378 	if(txt.match(/^[0-9.-]+$/)) return txt;
       
   379 	return;
       
   380 }
       
   381 
       
   382 
       
   383 function wrapalltext(node) {
       
   384     if(!node) node= document;
       
   385     var all = node.getElementsByTagNameNS(svgns,'text');
       
   386     var i=0;
       
   387     for (i=0; i<all.length; i++) {
       
   388 		var cur = all.item(i);
       
   389 		var w=0;
       
   390 		if (cur.hasAttribute('width')) {
       
   391 			w = whatSize(cur.getAttribute('width'));
       
   392 		}
       
   393 	if (w)	wraptext(cur,w)
       
   394 	}
       
   395 }
       
   396 
       
   397 
       
   398 function wraptext(cur,l) {
       
   399 	if(cur.firstChild.nodeType != 3)  return; // must be just a text node
       
   400 	if(cur.getBBox().width < l )  {
       
   401 		cur.firstChild.data = cur.firstChild.data.replace(/[\xad\u200b]/g,"");
       
   402 		return; // no need -- won't wrap
       
   403 	}
       
   404 	var t = cur.firstChild.data.replace(/\s+/," ");  // normalize all spaces
       
   405 	t = t.replace(/^ +/,"").replace(/ +$/,"");  // trim spaces
       
   406 	var words =splitup(t); 	// each word ends with the split character (if any)
       
   407 	if (words.length<2)  {
       
   408 		crush(cur, l);
       
   409 		return;
       
   410 	}
       
   411 	cur.removeChild(cur.firstChild)
       
   412 	var tspan = document.createElementNS(svgns,'tspan');
       
   413 	var first = tspan;	
       
   414 	cur.appendChild(tspan);
       
   415 	var txt = document.createTextNode(words[0]);
       
   416 	tspan.appendChild(txt);
       
   417 	tspan.setAttribute('x',cur.getAttribute('x'));	// Opera needs this
       
   418 	var nlines=1;
       
   419 	var zero =0;
       
   420 	for (i =1;i< words.length;i++) {
       
   421 		var was = txt.data;
       
   422 		txt.data+=words[i];
       
   423 		if (tspan.getComputedTextLength() -zero > l) { // if the line with this word at the end is bigger than the available space...
       
   424 			txt.data=was.replace(/ +$/,"").replace(/\xad(.)/,"$1").replace(/\u200b/g,""); // remove zero-width spaces and trailing spaces and soft hyphens
       
   425 			// if it's still too big then decrease the letter spacing
       
   426 			if( tspan.getComputedTextLength() > l ) crush(tspan,l);
       
   427 			tspan = document.createElementNS(svgns,'tspan');
       
   428 			tspan.setAttribute('dy',"1em");
       
   429 			nlines++;
       
   430 			tspan.setAttribute('x',cur.getAttribute('x'));
       
   431 			cur.appendChild(tspan);
       
   432 			txt = document.createTextNode('');
       
   433 			tspan.appendChild(txt);
       
   434 			zero = tspan.getComputedTextLength();
       
   435 			txt.data+=words[i];
       
   436 		}
       
   437 	}
       
   438 	txt.data=txt.data.replace(/ +$/,"").replace(/\xad(.)/,"$1").replace(/\u200b/g,""); // remove zero-width spaces and trailing spaces and soft hyphens
       
   439 	if( tspan.getComputedTextLength() > l ) 	crush(tspan,l);
       
   440 	var align =cur.getAttribute('dy');
       
   441 	if(align=='0.375em') {	// middle aligned
       
   442 		first.setAttribute('dy',((1-nlines ) / 2 + 0.375 )+"em");
       
   443 	}  else if(align=='0.75em' || align=='1em')  {  // top (or above) aligned
       
   444 		first.setAttribute('dy',align)	
       
   445 	}  else  { // bottom aligned (default)
       
   446 		first.setAttribute('dy',(1-nlines)+"em");
       
   447 	}
       
   448 }
       
   449 ]]>
       
   450   <!-- 
       
   451   dominant-baseline is not widely supported, but should indicate the vertical alignment of the text
       
   452   	mathematical = middle-aligned
       
   453   	hanging = top-aligned
       
   454   	ideographic = bottom aligned
       
   455   Since they're not widely supported, using dy is used instead. 
       
   456   Ideally we'd have
       
   457 	  top aligned: dy="1.5ex"
       
   458 	  middle aligned: dy="0.75ex"
       
   459 	  bottom aligned: dy="0ex"
       
   460 	  since in most fonts the top of the captial letters is about 0.5ex higher than the 
       
   461 	  	top of the lower case letters (1ex), hence 1.5ex for top-algined and half that for middle
       
   462   However, you can't add the em-based offset of multiple lines to the ex-based alignment, 
       
   463   	so we have to make the reasonably valid assumption that 1em = 2ex
       
   464   Which gives us: 
       
   465 	  top aligned: dy="0.75em"
       
   466 	  middle aligned: dy="0.375em"
       
   467 	  bottom aligned: dy="0em"
       
   468 	Since this is supported is Firefox 3.5, ASV and Opera 9, it's a much better way to handle 
       
   469 		he alighment than using the dominant-baseline approach
       
   470    -->
       
   471 </xsl:template>
       
   472 
       
   473 <xsl:template name="script-navcontrol">
       
   474 <!-- this should only be called on the SystemDefinition element -->
       
   475 var pandandzoom=null;
       
   476 function endpanning()
       
   477         {
       
   478         if(pandandzoom)
       
   479 	        {
       
   480     	    window.clearInterval(pandandzoom)
       
   481         	pandandzoom=null
       
   482         	}
       
   483         }
       
   484 
       
   485 function repeatpan(x,y)
       
   486         {
       
   487         endpanning()
       
   488         panning(x,y)
       
   489         pandandzoom = window.setInterval('panning('+x+','+y+')', 100);
       
   490         }
       
   491 
       
   492 function panning(x,y)
       
   493         {
       
   494         document.rootElement.currentTranslate.x += x
       
   495         document.rootElement.currentTranslate.y += y
       
   496         }
       
   497 
       
   498 function repeatzoom(z)
       
   499         {
       
   500         endpanning()
       
   501         zoom(z)
       
   502         pandandzoom = window.setInterval('zoom('+z+')', 100);
       
   503         }
       
   504 <![CDATA[
       
   505 function zoom(z)
       
   506 		{
       
   507 		var viewbox = document.documentElement.getAttribute("viewBox").split(' ');
       
   508  		var x = Number(viewbox[0]);
       
   509  		var y = Number(viewbox[1]);
       
   510  		var width = Number(viewbox[2]);
       
   511  		var height = Number(viewbox[3]);
       
   512  		if( window.innerWidth==0 || window.innerHeight ==0 || height ==0) {return}
       
   513  		var s = width  / window.innerWidth;
       
   514  		if ( width / height < window.innerWidth / window.innerHeight)
       
   515  			{
       
   516 			s = height  / window.innerHeight;
       
   517 			width = window.innerWidth * s;
       
   518 			}
       
   519 		else	
       
   520 			{
       
   521  			height = window.innerHeight * s;
       
   522  			}
       
   523  			
       
   524  		x = x - 0.5* (width - viewbox[2]) + ( -document.rootElement.currentTranslate.x ) * s  / document.rootElement.currentScale ;
       
   525 		y = y - 0.5* (height - viewbox[3]) + ( -document.rootElement.currentTranslate.y ) * s  / document.rootElement.currentScale ;
       
   526 		width = width / document.rootElement.currentScale;
       
   527 		height = height / document.rootElement.currentScale;
       
   528         document.rootElement.currentTranslate.x=
       
   529         	document.rootElement.currentTranslate.x *z - 0.5*window.innerWidth* (z -1 )
       
   530         document.rootElement.currentTranslate.y=
       
   531         	document.rootElement.currentTranslate.y *z - 0.5*window.innerHeight* (z -1 )
       
   532         document.rootElement.currentScale*=z
       
   533 		}
       
   534 ]]>
       
   535 </xsl:template>
       
   536 
       
   537 <xsl:template name="script-float-legend">
       
   538 function movelegend(id)
       
   539 	{
       
   540 	var parent = document.getElementById(id);
       
   541 	var legend = document.getElementById('legend-box');
       
   542 	parent.appendChild(legend);
       
   543 	}
       
   544 </xsl:template>
       
   545 
       
   546 <!-- well known patterns -->
       
   547 
       
   548 <xsl:template name="default-new-pattern">
       
   549 	<radialGradient id="Patternradial-grad"  gradientUnits="objectBoundingBox" cx="50%" cy="50%" r="70%">
       
   550 		<stop offset="0%" stop-color="white" stop-opacity="1"/>
       
   551 		<stop offset="100%" stop-opacity="0" stop-color="white" />
       
   552 	</radialGradient>
       
   553 </xsl:template>
       
   554 
       
   555 <xsl:template name="default-ref-pattern"> 	<!-- diagonal line pattern -->
       
   556 	<linearGradient id="Patternstriped-diag-up" spreadMethod="repeat" gradientUnits="userSpaceOnUse" x1="0" x2="3" y1="0" y2="3">
       
   557 		<stop offset="0%" stop-opacity="0" stop-color="white" />
       
   558 		<stop offset="20%" stop-color="#ccc" stop-opacity="1" />
       
   559 		<stop offset="40%" stop-opacity="0" stop-color="white" />
       
   560 		<stop offset="100%" stop-opacity="0" stop-color="white" />
       
   561 	</linearGradient>
       
   562 </xsl:template>
       
   563 
       
   564 <xsl:template name="default-X-pattern"> 	<!-- big dark X -->
       
   565 	<pattern id="Patternbig-X" patternUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%" viewBox="0 0 10 10">
       
   566 		<path d="M 1 1 L 9 9 M 1 9  L 9 1" stroke="#555" stroke-width="1.15" stroke-linecap="round"/>
       
   567 	</pattern> 
       
   568 </xsl:template>
       
   569 
       
   570 
       
   571 
       
   572 <xsl:template name="nav-control-patterns"> 	<!-- patterns needed for the naviagiton control -->
       
   573     <radialGradient id="Patternoutgrad"  cx="50%" cy="50%" r="100%" fx="50%" fy="50%">
       
   574        <stop offset="36%" stop-color="white" stop-opacity="0"/>
       
   575        <stop offset="43%" stop-color="white" stop-opacity="0.6" />
       
   576        <stop offset="50%" stop-color="white"  stop-opacity="0"/>
       
   577        <stop offset="100%" stop-color="black"  stop-opacity="0"/>
       
   578      </radialGradient>
       
   579      <radialGradient id="Patterningrad"  cx="50%" cy="50%" r="100%" fx="50%" fy="50%">
       
   580        <stop offset="0%" stop-color="white" stop-opacity="0.45"/>
       
   581        <stop offset="36%" stop-color="yellow" stop-opacity="0"/>
       
   582        <stop offset="43%" stop-color="yellow" stop-opacity="0.6" />
       
   583        <stop offset="50%" stop-color="yellow"  stop-opacity="0"/>
       
   584        <stop offset="100%" stop-color="black"  stop-opacity="0"/>
       
   585      </radialGradient>
       
   586 </xsl:template>
       
   587 
       
   588 
       
   589 <!-- well-known border shapes -->
       
   590 
       
   591 
       
   592 <xsl:template name="default-box-border">
       
   593     <symbol id="Borderbox" viewBox="0 0 20 20">
       
   594       <path d="M 0 0 L 0 20 L 20 20 L 20 0 z" stroke="black"/>
       
   595     </symbol>
       
   596 </xsl:template>
       
   597 <xsl:template name="default-clipLB-border">
       
   598     <symbol id="Borderbox-clipLB" viewBox="0 0 20 20">
       
   599       <path d="M 0 0 L 0 15 L 5 20 L 20 20 L 20 0 z" stroke="black"/>
       
   600     </symbol>
       
   601 </xsl:template>
       
   602 <xsl:template name="default-clipLT-border">
       
   603     <symbol id="Borderbox-clipLT" viewBox="0 0 20 20">
       
   604       <path d="M 5 0 L 0 5 L 0 20 L 20 20 L 20 0 z" stroke="black"/>
       
   605     </symbol>
       
   606 </xsl:template>
       
   607 <xsl:template name="default-clipRB-border">
       
   608     <symbol id="Borderbox-clipRB" viewBox="0 0 20 20">
       
   609       <path d="M 0 0 L 0 20 L 15 20 L 20 15 L 20 0 z" stroke="black"/>
       
   610     </symbol>
       
   611 </xsl:template>
       
   612 <xsl:template name="default-clipRT-border">
       
   613     <symbol id="Borderbox-clipRT" viewBox="0 0 20 20">
       
   614       <path d="M 0 0 L 0 20 L 20 20 L 20 5 L 15 0 z" stroke="black"/>
       
   615     </symbol>
       
   616 </xsl:template>
       
   617 <xsl:template name="default-clipAll-border">
       
   618     <symbol id="Borderbox-clipAll" viewBox="0 0 20 20">
       
   619       <path d="M 5 0 L 0 5 L 0 15 L 5 20 L 15 20 L 20 15 L 20 5 L 15 0 z" stroke="black"/>
       
   620     </symbol>
       
   621 </xsl:template>
       
   622 <xsl:template name="default-round-border">
       
   623 	<symbol id="Borderround" viewBox="0 0 20 20">
       
   624 		<circle cx="10" cy="10" r="10" stroke="black" />
       
   625 	</symbol>
       
   626 </xsl:template>
       
   627 <xsl:template name="default-hexagon-border">
       
   628 	<symbol id="Borderhexagon" viewBox="0 0 20 20">
       
   629 		<path d="M 0 10 L 5.8 0 L 14.2 0 L 20 10 L 14.2 20 L 5.8 20 z" stroke="black" />
       
   630 	</symbol>
       
   631 </xsl:template>
       
   632 
       
   633 <!-- end borders -->
       
   634 
       
   635 		<!-- overridden by output of shapes.xsl -->
       
   636 <xsl:template match="SystemDefinition" mode="shapes">
       
   637 	<xsl:call-template name="default-new-pattern"/>
       
   638 	<xsl:call-template name="default-ref-pattern"/>
       
   639 	<xsl:call-template name="default-X-pattern"/> 
       
   640 	<xsl:if test="not(@static='true') and (@navctrl)">
       
   641 		<xsl:call-template name="nav-control-patterns"/> 
       
   642 	</xsl:if>
       
   643 		<!-- borders to use for OSD components -->
       
   644 
       
   645 	<xsl:call-template name="default-box-border"/>
       
   646 	<xsl:call-template name="default-clipLB-border"/>
       
   647 	<xsl:call-template name="default-clipLT-border"/>
       
   648 	<xsl:call-template name="default-clipRB-border"/>
       
   649 	<xsl:call-template name="default-clipRT-border"/>
       
   650 	<xsl:call-template name="default-clipAll-border"/>
       
   651 </xsl:template>
       
   652 
       
   653 
       
   654 <xsl:template match="component|collection|package|layer" mode="id"><xsl:value-of select="@id"/></xsl:template>
       
   655 
       
   656 <xsl:template name="linkable-content"><xsl:param name="show"/>
       
   657 	<xsl:variable name="found">
       
   658 		<xsl:apply-templates select="." mode="has-link"/>
       
   659 	</xsl:variable>
       
   660 	<xsl:choose> <!-- don't use <a> unless there is a valid link -->
       
   661 		<xsl:when test="$found='' or parent::legend">
       
   662 			<xsl:copy-of select="$show"/>				
       
   663 		</xsl:when>
       
   664 		<xsl:otherwise>
       
   665 			<a>
       
   666 				<xsl:apply-templates select="." mode="link-label"/>
       
   667 				<xsl:copy-of select="$show"/>
       
   668 			</a>
       
   669 		</xsl:otherwise>
       
   670 	</xsl:choose>
       
   671 </xsl:template>
       
   672 
       
   673 <xsl:template mode="validate" match="node()" priority="-4"/>
       
   674 <xsl:template mode="validate" match="*" priority="-2"><xsl:apply-templates mode="validate" select="*"/></xsl:template>
       
   675 
       
   676 
       
   677 <xsl:template name="display-name">
       
   678 	<xsl:apply-templates select="." mode="text-filter"/>
       
   679 	<xsl:if test="@font">
       
   680 		<xsl:attribute name="style">font-family: '<xsl:value-of select="@font"/>'</xsl:attribute>
       
   681 	</xsl:if>
       
   682 	<xsl:call-template name="name-value"/>
       
   683 </xsl:template>
       
   684 
       
   685 <xsl:template name="name-value">
       
   686 	<xsl:choose>
       
   687 		<xsl:when test="self::cmp or self::cbox  or self::legend or self::note or self::layer[legend|note]">
       
   688 			<xsl:apply-templates select="." mode="name"/>
       
   689 		</xsl:when>
       
   690 		<xsl:when test="@abbrev"><xsl:value-of select="@abbrev"/></xsl:when>
       
   691 		<xsl:when test="@label"><xsl:value-of select="@label"/></xsl:when> <!-- for legends -->
       
   692 		<xsl:when test="@lookup"><xsl:value-of select="@lookup"/></xsl:when> <!-- for legends -->
       
   693 		<xsl:when test="$Use-as-name!='name' and @*[name()=$Use-as-name]"><xsl:value-of select="@*[name()=$Use-as-name]"/></xsl:when>
       
   694 		<xsl:when test="@name"><xsl:value-of select="@name"/></xsl:when>
       
   695 		<xsl:otherwise><xsl:value-of select="@id"/></xsl:otherwise>
       
   696 	</xsl:choose>
       
   697 </xsl:template>
       
   698 
       
   699 
       
   700 <!-- ============ hyperlinks ============ -->
       
   701 
       
   702 <xsl:template match="*" mode="has-link"/>
       
   703 <xsl:template match="*[@id and ancestor::SystemDefinition/@base]" mode="has-link">1</xsl:template>
       
   704 
       
   705 <xsl:template match="*" mode="link-label"/>
       
   706 <xsl:template match="*[@id]" mode="link-label">
       
   707 	<xsl:attribute name="target">details</xsl:attribute>
       
   708 	<xsl:attribute name="xlink:href"><xsl:value-of select="ancestor::SystemDefinition/@base"/>/<xsl:choose>
       
   709 		<xsl:when test="self::package[parent::package]">SubBlocks</xsl:when>
       
   710 		<xsl:when test="self::package">Blocks</xsl:when>
       
   711 		<xsl:when test="self::layer">Layers</xsl:when>
       
   712 		<xsl:when test="self::component">Components</xsl:when>
       
   713 		<xsl:when test="self::collection">Collections</xsl:when>
       
   714 		<xsl:otherwise>
       
   715 			<xsl:call-template name="Caller-Error">
       
   716 				<xsl:with-param name="text">Invalid element <xsl:value-of select="name()"/> id="<xsl:value-of select="@id"/>". Cannot generate link.</xsl:with-param>
       
   717 			</xsl:call-template>
       
   718 		</xsl:otherwise>
       
   719 	</xsl:choose>/<xsl:value-of select="@name"/>.html</xsl:attribute>
       
   720 </xsl:template>
       
   721 
       
   722 <!-- ============ styles ============ -->
       
   723 
       
   724 
       
   725 <xsl:template name="default-font">
       
   726 	<xsl:choose>
       
   727 		<xsl:when test="ancestor-or-self::SystemDefinition[@font]">'<xsl:value-of select="ancestor-or-self::SystemDefinition/@font"/>'</xsl:when>
       
   728 		<xsl:otherwise>Arial</xsl:otherwise>
       
   729 	</xsl:choose>
       
   730 </xsl:template>
       
   731 
       
   732 <xsl:template name="title-line-height">
       
   733 	<xsl:choose>
       
   734 		<xsl:when test="number(ancestor-or-self::SystemDefinition/systemModel/meta/legend/@title-scale)">
       
   735 			<xsl:value-of select="4.3 * ancestor-or-self::SystemDefinition/systemModel/meta/legend/@title-scale"/> <!-- scale 12pt by specified factor-->
       
   736 		</xsl:when>
       
   737 		<xsl:when test="ancestor-or-self::SystemDefinition/systemModel/meta/legend[@percent-width or @maxscale]">4.233</xsl:when> <!-- 12pt -->
       
   738 		<xsl:when test="ancestor-or-self::SystemDefinition/@width &gt; $large-width">6.3495</xsl:when> <!-- 18 pt -->
       
   739 		<xsl:otherwise>4.3</xsl:otherwise> <!-- 12pt -->
       
   740 	</xsl:choose>		
       
   741 </xsl:template>
       
   742 
       
   743 
       
   744 <!-- ============ display styles ============ -->
       
   745 
       
   746 <xsl:template name="styles"><xsl:param name="for" select="'bg'"/>
       
   747 	<xsl:variable name="st0">
       
   748 		<xsl:apply-templates select="." mode="display-style"/></xsl:variable>
       
   749 	<xsl:variable name="st1">
       
   750 		<xsl:choose>
       
   751 			<xsl:when test="$for='label' and @label-bg">fill:<xsl:value-of select="@label-bg"/>!important;</xsl:when>
       
   752 			<xsl:when test="@bg">fill:<xsl:value-of select="@bg"/>!important;</xsl:when>
       
   753 		</xsl:choose>
       
   754 	</xsl:variable>
       
   755 	<xsl:if test="$st0!='' or $st1!=''">
       
   756 	<xsl:attribute name="style">
       
   757 		<xsl:value-of select="$st0"/>
       
   758 		<xsl:if test="$st0!='' and $st1!='' and substring($st0,string-length($st0))!=';'">;</xsl:if>
       
   759 		<xsl:value-of select="$st1"/>
       
   760 	</xsl:attribute>
       
   761 	</xsl:if>
       
   762 </xsl:template>
       
   763 
       
   764 <xsl:template name="gradient-direction"> <!-- calaulate the x1, etc attrbiutes from the dir ratio string. clip each to the range -1..1 -->
       
   765   <xsl:param name="dx" select="1"/>
       
   766   <xsl:param name="dy" select="0"/>
       
   767       <xsl:if test="$dx!='' and $dy!=''">
       
   768         <xsl:attribute  name="x1">
       
   769           <xsl:choose>
       
   770             <xsl:when test="$dx &lt; -1">100%</xsl:when>
       
   771             <xsl:when test="$dx &gt;= 0">0%</xsl:when>
       
   772             <xsl:otherwise><xsl:value-of select="-$dx * 100"/>%</xsl:otherwise>          
       
   773           </xsl:choose>
       
   774        </xsl:attribute>
       
   775         <xsl:attribute  name="x2">
       
   776           <xsl:choose>
       
   777             <xsl:when test="$dx &gt; 1">100%</xsl:when>
       
   778             <xsl:when test="$dx &lt;= 0">0%</xsl:when>
       
   779             <xsl:otherwise><xsl:value-of select="$dx * 100"/>%</xsl:otherwise>          
       
   780           </xsl:choose>
       
   781        </xsl:attribute>
       
   782         <xsl:attribute  name="y1">
       
   783           <xsl:choose>
       
   784             <xsl:when test="$dy &lt; -1">100%</xsl:when>
       
   785             <xsl:when test="$dy &gt;= 0">0%</xsl:when>
       
   786             <xsl:otherwise><xsl:value-of select="-$dy * 100"/>%</xsl:otherwise>          
       
   787           </xsl:choose>
       
   788        </xsl:attribute>
       
   789         <xsl:attribute  name="y2">
       
   790           <xsl:choose>
       
   791             <xsl:when test="$dy &gt;1">100%</xsl:when>
       
   792             <xsl:when test="$dy &lt;= 0">0%</xsl:when>
       
   793             <xsl:otherwise><xsl:value-of select="$dy * 100"/>%</xsl:otherwise>          
       
   794           </xsl:choose>
       
   795        </xsl:attribute>  
       
   796       </xsl:if>
       
   797 </xsl:template>
       
   798 
       
   799 <xsl:template name="gradient-angle"> <!-- calaulate the x1, etc attrbiutes from the dir ratio string. clip each to the range -1..1 -->
       
   800   <xsl:param name="theta" select="0"/>
       
   801 	<xsl:call-template name="gradient-direction">
       
   802 	  <xsl:with-param name="dx" select="m:cos($theta * m:constant('PI',6) div 180)"/>
       
   803 	  <xsl:with-param name="dy" select="-m:sin($theta * m:constant('PI',6) div 180)"/>
       
   804 	</xsl:call-template>
       
   805 </xsl:template>
       
   806 
       
   807 
       
   808 <!-- provide a gradient of multiple colours for the fill of an item -->
       
   809 <xsl:template name="multi-color-grad">
       
   810 	<xsl:param name="c" /> <!--  nodeset of either values or values to look up in $key -->
       
   811 	<xsl:param name="key" /> <!-- the style ID to lookup the value. Optional. If not set, the value of $c is the value -->
       
   812 	<xsl:param name="blur" /> <!-- % to blur 100% mean to blur to the full size of each gradient section -->
       
   813 	<xsl:param name="dir" /> <!-- direction ratio in the form dx:dy, where each has a range from -1..1 -->
       
   814 	<xsl:param name="angle" /> <!-- angle : use this instead of dir when possible -->
       
   815 	<xsl:if test="($key!='' and count(key($key,$c)/@value) &gt; 1) or ($key='' and count($c) &gt; 1)  "><!-- only define if there's more than one match -->
       
   816 		<linearGradient>
       
   817 	        <xsl:attribute  name="id">bg<xsl:apply-templates select="." mode="id"/></xsl:attribute>
       
   818 			<xsl:choose>
       
   819 				<xsl:when test="function-available('m:sin') and function-available('m:cos') and function-available('m:constant') and $angle!=''">
       
   820 					<xsl:call-template name="gradient-angle">
       
   821 						<xsl:with-param name="theta" select="$angle" />
       
   822 					</xsl:call-template>
       
   823 				</xsl:when>
       
   824 				<xsl:otherwise>
       
   825 					<xsl:call-template name="gradient-direction">
       
   826 					  <xsl:with-param name="dx" select="substring-before($dir,':')"/>
       
   827 					  <xsl:with-param name="dy" select="substring-after($dir,':')"/>
       
   828 					</xsl:call-template>
       
   829 				</xsl:otherwise>
       
   830 			</xsl:choose>
       
   831 			<xsl:variable name="blur0" select="$blur div count($c)" />
       
   832 			<xsl:for-each select="$c">
       
   833 				<xsl:sort />
       
   834 				<xsl:variable name="value">
       
   835 					<xsl:choose>
       
   836 						<xsl:when test="$key=''"><xsl:value-of select="."/></xsl:when>
       
   837 						<xsl:otherwise><xsl:value-of select="key($key,.)/@value"/></xsl:otherwise>
       
   838 					</xsl:choose>
       
   839 				 </xsl:variable>
       
   840 				<stop offset="{100* (position()-1) div  last() + $blur0}%" stop-color="{$value}" />
       
   841 				<xsl:if test="position()!=last()">
       
   842 					<stop offset="{100* position() div  last() - $blur0}%" stop-color="{$value}" />
       
   843 				</xsl:if>
       
   844 			</xsl:for-each>
       
   845 		</linearGradient>
       
   846 	</xsl:if>
       
   847 </xsl:template>
       
   848 <xsl:template mode="multi-color" match="*" priority="-1"/> <!-- this is handled in the generated XSLT, so do nothing by default -->
       
   849 
       
   850 <xsl:template mode="multi-color" match="*[meta/generator-color]">
       
   851   <xsl:call-template name="multi-color-grad">
       
   852    <xsl:with-param name="key" select="'styled'"/>
       
   853    <xsl:with-param name="c" select="meta/generator-color/@ref"/>
       
   854    <xsl:with-param name="blur" select="0"/>
       
   855   </xsl:call-template>
       
   856 </xsl:template>
       
   857 
       
   858 
       
   859 <xsl:template match="*" mode="display-style-color" priority="-2"/>
       
   860 <xsl:template match="*" mode="animate-color" priority="-2"/><!-- change from -2 to disable -->
       
   861 
       
   862 
       
   863 <xsl:template match="*[@generator-color]" mode="animate-color" priority="4">
       
   864 	<xsl:if test="not(ancestor::SystemDefinition/@static='true')">
       
   865 		<set attributeName="opacity" attributeType="XML" to="0.5" fill="remove" begin="{@generator-color}.mouseover" end="{@generator-color}.mouseout"/>		
       
   866 	</xsl:if>
       
   867 </xsl:template>
       
   868 <xsl:template match="*[meta/generator-color]" mode="animate-color" priority="4">
       
   869 	<xsl:if test="not(ancestor::SystemDefinition/@static='true')">
       
   870 		<xsl:for-each select="meta/generator-color">
       
   871 			<set attributeName="opacity" attributeType="XML" to="0.5" fill="remove" begin="{@ref}.mouseover" end="{@ref}.mouseout"/>		
       
   872 		</xsl:for-each>
       
   873 	</xsl:if>
       
   874 </xsl:template>
       
   875 
       
   876 
       
   877 <!--  generated overrides -->
       
   878   
       
   879 
       
   880 <xsl:template match="*[@generator-color]" mode="display-style-color" priority="8">
       
   881 	<xsl:for-each select="key('styled',@generator-color)">
       
   882 		<xsl:value-of select="@value | @default"/>	<!-- can't have both -->
       
   883 	</xsl:for-each>
       
   884 </xsl:template>
       
   885 
       
   886 
       
   887 <xsl:template match="*[count(meta/generator-color)=1]" mode="display-style-color" priority="8">
       
   888 	<xsl:for-each select="key('styled',meta/generator-color/@ref)">
       
   889 		<xsl:value-of select="@value | @default"/>	<!-- can't have both -->
       
   890 	</xsl:for-each>
       
   891 </xsl:template>
       
   892 
       
   893 <xsl:template match="*[count(meta/generator-color) &gt; 1]" mode="display-style-color" priority="8">
       
   894 	<xsl:variable name="ref" select="key('styled',meta/generator-color/@ref)"/>
       
   895 	<xsl:choose>
       
   896 		<xsl:when test="count($ref/@value)=1">
       
   897 			<xsl:value-of select="$ref/@value"/>
       
   898 		</xsl:when>
       
   899 		<xsl:when test="count($ref/@value)=0">
       
   900 			<xsl:value-of select="$ref/@default[last()]"/>
       
   901 		</xsl:when>
       
   902 		<xsl:otherwise>
       
   903 			<xsl:text>url(#bg</xsl:text><xsl:apply-templates select="." mode="id"/><xsl:text>)</xsl:text>
       
   904 		</xsl:otherwise>
       
   905 	</xsl:choose>
       
   906 </xsl:template>
       
   907 
       
   908 
       
   909 <xsl:template match="*[@generator-text-highlight]" mode="text-filter"  priority="8">
       
   910 		<xsl:attribute name="filter">url(<xsl:for-each select="key('styled',@generator-text-highlight)">
       
   911 		<xsl:value-of select="@value | @default"/>	<!-- can't have both -->
       
   912 	</xsl:for-each>)</xsl:attribute>
       
   913 </xsl:template>
       
   914 
       
   915 <xsl:template match="*[@generator-highlight]" mode="filter" priority="8">
       
   916 	<xsl:attribute name="filter">url(<xsl:for-each select="key('styled',@generator-highlight)">
       
   917 		<xsl:value-of select="@value | @default"/>	<!-- can't have both -->
       
   918 	</xsl:for-each>)</xsl:attribute>
       
   919 </xsl:template>
       
   920 
       
   921 <xsl:template match="*[@generator-overlay|meta/generator-overlay]" mode="overlays" priority="8">
       
   922 	<xsl:for-each select="key('styled',@generator-overlay|meta/generator-overlay/@ref)">
       
   923 		<o>
       
   924 			<xsl:value-of select="@value | @default"/>	<!-- can't have both -->
       
   925 		</o>
       
   926 	</xsl:for-each>
       
   927 </xsl:template>
       
   928 
       
   929 <xsl:template match="*[@generator-border]" mode="shape" priority="8">
       
   930 	<xsl:for-each select="key('styled',@generator-border)">
       
   931 		<xsl:value-of select="@value | @default"/>	<!-- can't have both -->
       
   932 	</xsl:for-each>
       
   933 </xsl:template>
       
   934 
       
   935 <xsl:template match="*" mode="display-style">
       
   936 	<xsl:variable name="color"><xsl:apply-templates select="." mode="display-style-color"/></xsl:variable>
       
   937 	<xsl:if test="$color!=''">fill:<xsl:value-of select="$color"/>;</xsl:if>
       
   938 	<xsl:for-each select="@generator-style | meta/generator-style/@ref">
       
   939 		<xsl:for-each select="key('styled',.)">
       
   940 			<xsl:value-of select="concat(@value | @default,';')"/><!-- can't have both -->
       
   941 		</xsl:for-each>
       
   942 	</xsl:for-each>
       
   943 	<xsl:apply-templates select="." mode="display-style-aux"/>
       
   944 </xsl:template>
       
   945   
       
   946 <!--  defaults -->
       
   947   
       
   948 <xsl:template match="*" mode="display-style-aux" priority="-2"/>
       
   949 <xsl:template match="component" mode="display-style-aux" priority="-1">stroke-width:<xsl:choose>
       
   950 	<xsl:when test="@plugin">2</xsl:when>
       
   951 	<xsl:otherwise>0.4</xsl:otherwise>
       
   952 </xsl:choose>;</xsl:template>
       
   953 
       
   954 <xsl:template match="component|cmp" mode="display-style-color" priority="-1">grey</xsl:template>
       
   955 
       
   956 <xsl:template match="*" mode="overlay-styles">
       
   957 	<!-- overlays just retruns each overlay pattern, this turns them into actual styles -->
       
   958 	<xsl:variable name="o">
       
   959 		<xsl:apply-templates select="." mode="overlays"/>
       
   960 	</xsl:variable>
       
   961 	<xsl:for-each select="exslt:node-set($o)/*">
       
   962 		<xsl:copy>fill:<xsl:if test=".=''">none</xsl:if>
       
   963 		<xsl:if test=".!=''">url(<xsl:value-of select="."/>)</xsl:if>
       
   964 		<xsl:text>; stroke: none; stroke-width: 0;</xsl:text>
       
   965 		</xsl:copy>
       
   966 	</xsl:for-each>
       
   967 </xsl:template>
       
   968 
       
   969 <xsl:template match="*" mode="overlays" priority="-3"/>
       
   970 
       
   971 <xsl:template match="component" mode="overlays" priority="-2">
       
   972 	<xsl:if test="@introduced = ancestor::SystemDefinition/@ver"><o>#Patternradial-grad</o></xsl:if>
       
   973 	<xsl:if test="@purpose='development' "><o>#Patternstriped-diag-up</o></xsl:if>
       
   974 </xsl:template>
       
   975 
       
   976 <xsl:template match="component|cmp" mode="overlays" priority="-3"/>
       
   977 
       
   978 <xsl:template match="component|cmp" mode="shape" priority="-1">#Borderbox</xsl:template>
       
   979 
       
   980 <!-- ====== legend ============= -->
       
   981 
       
   982 <xsl:include href="legend.xsl"/>
       
   983 <!-- end legend -->
       
   984 
       
   985 
       
   986 <!-- ====== drawing ============= -->
       
   987 
       
   988 <xsl:template match="*"  priority="-1">
       
   989 		<xsl:call-template name="Caller-Error">
       
   990 			<xsl:with-param name="text">Unrecognised elementn <xsl:value-of select="name()"/> not supported</xsl:with-param>
       
   991 		</xsl:call-template>
       
   992 </xsl:template>
       
   993 
       
   994 <xsl:template match="meta" priority="-1">
       
   995 	<xsl:if test="not(following::meta[@rel=current()/@rel])">
       
   996 		<xsl:call-template name="Caller-Note">
       
   997 			<xsl:with-param name="text">meta rel="<xsl:value-of select="@rel"/>" not supported</xsl:with-param>
       
   998 		</xsl:call-template>
       
   999 	</xsl:if>
       
  1000 	<xsl:call-template name="Caller-Debug">
       
  1001 		<xsl:with-param name="text">meta rel="<xsl:value-of select="@rel"/>" in <xsl:value-of select="../@id"/> not supported</xsl:with-param>
       
  1002 	</xsl:call-template>
       
  1003 </xsl:template>
       
  1004 
       
  1005 <xsl:template match="meta[@rel='styling' or @rel='Generic' or not(@rel) or @rel='Dependencies' or starts-with(@rel,'model-') or @rel='layer-group' or @rel='config'  or @rel='testbuild']"/>
       
  1006 	<!-- no diagram data in these-->
       
  1007 
       
  1008 <xsl:template match="meta[@rel='model-levels']"/> <!--  by default, show no level titles -->
       
  1009 
       
  1010 <!-- global stuff is stuff which is drawn outside of any system model item -->
       
  1011 <xsl:template match="*" mode="global" priority="-1"/>
       
  1012 
       
  1013 <!-- ====== layer groups  ============= -->
       
  1014 
       
  1015 <xsl:template match="meta[@rel='layer-group']" mode="global">
       
  1016 	<xsl:apply-templates select="layer-group" mode="lgrp">
       
  1017 		<!-- start as wide as possible and go inward -->
       
  1018 		<xsl:with-param name="left" select="0"/>
       
  1019 		<xsl:with-param name="right" select="ancestor::SystemDefinition/@width"/> 
       
  1020 	</xsl:apply-templates>
       
  1021 </xsl:template>
       
  1022 
       
  1023 
       
  1024 <xsl:template match="layer-group" mode="lgrp">
       
  1025 	<xsl:param name="left"/><xsl:param name="right"/>
       
  1026 	<xsl:variable name="From" select="ancestor::systemModel/layer[@id=current()/@from]"/>
       
  1027 	<xsl:variable name="To" select="ancestor::systemModel/layer[@id=current()/@to]"/>
       
  1028 	<xsl:choose>
       
  1029 		<xsl:when test="not($From)">
       
  1030 			<xsl:call-template name="Caller-Error">
       
  1031 				<xsl:with-param name="text">layer "<xsl:value-of select="@from"/>" does not exist</xsl:with-param>
       
  1032 			</xsl:call-template>
       
  1033 		</xsl:when>
       
  1034 		<xsl:when test="not($To)">
       
  1035 			<xsl:call-template name="Caller-Error">
       
  1036 				<xsl:with-param name="text">layer "<xsl:value-of select="@to"/>" does not exist</xsl:with-param>
       
  1037 			</xsl:call-template>
       
  1038 		</xsl:when>
       
  1039 		<xsl:when test="not($From/following-sibling::layer[@id=current()/@to])">
       
  1040 			<xsl:call-template name="Caller-Error">
       
  1041 				<xsl:with-param name="text">"<xsl:value-of select="@from"/>" is after "<xsl:value-of select="@to"/>"</xsl:with-param>
       
  1042 			</xsl:call-template>
       
  1043 		</xsl:when>
       
  1044 		<xsl:when test="$To[@span]">
       
  1045 			<xsl:call-template name="Caller-Error">
       
  1046 				<xsl:with-param name="text">Layer group cannot be bounded by spanned layer "<xsl:value-of select="@to"/>"</xsl:with-param>
       
  1047 			</xsl:call-template>
       
  1048 		</xsl:when>
       
  1049 		<xsl:when test="$From[@span]">
       
  1050 			<xsl:call-template name="Caller-Error">
       
  1051 				<xsl:with-param name="text">Layer group cannot be bounded by spanned layer "<xsl:value-of select="@from"/>"</xsl:with-param>
       
  1052 			</xsl:call-template>
       
  1053 		</xsl:when>
       
  1054 		<xsl:otherwise>
       
  1055 			<xsl:variable name="parent-to" select="count(ancestor::layer-group[@to=current()/@to])"/>
       
  1056 			<xsl:variable name="child-to" select="1+ count(descendant::layer-group[@to=current()/@to])"/>
       
  1057 			<xsl:variable name="child-from" select="1+ count(descendant::layer-group[@from=current()/@from])"/>
       
  1058 			<xsl:variable name="between" select="$From/following-sibling::layer[following-sibling::layer[@id=current()/@to]]"/>
       
  1059 			<xsl:variable name="height" select="sum($From/@height | $From/@padding-top | $To/@height | $To/@padding-bottom |$between/@height | $between/@padding-top | $between/@padding-bottom) +
       
  1060 	 			$lgrpDx *  ($child-to+ $child-from) + $groupDy * (1 + count($between))"/>
       
  1061 			<xsl:variable name="start">
       
  1062 				<xsl:choose>
       
  1063 					<xsl:when test="$To/following-sibling::layer[not(@span)]">
       
  1064 					<xsl:value-of select="sum($To/following-sibling::layer[not(@span)]/@*[name()='height' or name()='padding-bottom' or name()='padding-top'])  
       
  1065 						+ $groupDy * count($To/following-sibling::layer[not(@span)])  + $lgrpDx *  $parent-to "/>
       
  1066 					</xsl:when>
       
  1067 					<xsl:otherwise>
       
  1068 						<xsl:value-of select="$lgrpDx *  $parent-to"/>
       
  1069 					</xsl:otherwise>
       
  1070 				</xsl:choose>
       
  1071 			</xsl:variable>
       
  1072 			<xsl:variable name="to-name" select="@to"/>
       
  1073 			<xsl:variable name="from-name" select="@from"/>
       
  1074 			<g class="{name()}">
       
  1075 				<rect width="{$right - $left}" height="{$height}" x="{$left}" y="{$start}" rx="{$lyrTitleBox*0.5}"  fill="{@color}"/>
       
  1076 				<xsl:if test="@label">
       
  1077 					<text text-anchor="middle" dy="0.375em" class="lgrp" transform="rotate(-90)" y="{$left + 0.5 * $lgrpLabelDx}" width="{$height}" x="{- ($start + 0.5 * $height)}">
       
  1078 						<xsl:value-of select="@label"/>
       
  1079 					</text>
       
  1080 				</xsl:if>
       
  1081 			</g>
       
  1082 			<xsl:variable name="dx">
       
  1083 				<xsl:choose>
       
  1084 					<xsl:when test="@label"><xsl:value-of select="$lgrpLabelDx"/></xsl:when>
       
  1085 					<xsl:otherwise><xsl:value-of select="$lgrpDx * 0.75"/></xsl:otherwise>
       
  1086 				</xsl:choose>
       
  1087 			</xsl:variable>		
       
  1088 			<xsl:apply-templates select="layer-group" mode="lgrp">
       
  1089 				<xsl:with-param name="left" select="$left + $dx"/>
       
  1090 				<xsl:with-param name="right" select="$right - $lgrpDx"/>
       
  1091 			</xsl:apply-templates>
       
  1092 		</xsl:otherwise>
       
  1093 	</xsl:choose>
       
  1094 
       
  1095 </xsl:template>
       
  1096 
       
  1097 <!-- ====== layers  ============= -->
       
  1098 
       
  1099 <xsl:template match="layer">
       
  1100 	<xsl:variable name="y" select="sum(@padding-top|following-sibling::layer[not(@span)]/@*[name()='height'  or name()='padding-bottom' or name()='padding-top']) + count(following::layer[not(@span)]) * $groupDy"/>
       
  1101 		
       
  1102 	<g id="{@id}" transform="translate({ancestor::SystemDefinition/@padding-left - 3.5 - $lyrTitleBox } {$y})">
       
  1103 		<xsl:call-template name="my-class"/>
       
  1104 		<xsl:apply-templates select="." mode="filter"/>
       
  1105 		<xsl:apply-templates select="." mode="animate-color"/>	
       
  1106         <xsl:apply-templates select="." mode="multi-color"/>	
       
  1107         <xsl:variable name="show-content" select="not(ancestor::SystemDefinition[@detail='layer' and not(@levels='show')])"/> <!-- only show if showing content -->
       
  1108         <xsl:if test="$show-content"> <!-- only show if showing content -->
       
  1109 			<xsl:call-template name="linkable-content">
       
  1110 				<xsl:with-param name="show">
       
  1111 					<rect x="0.3" y="0.3" width="{$lyrTitleBox}" rx="{$lyrTitleBox * 0.5}" ry="{$lyrTitleBox * 0.5}" class="{name()}" height="{@height}">
       
  1112 						<xsl:call-template name="styles"><xsl:with-param name="for" select="'label'"/></xsl:call-template>
       
  1113 					</rect>
       
  1114 					<text  text-anchor="middle" dy="0.375em" class="layer" transform="rotate(-90)" 
       
  1115 						 y="{$lyrTitleBox * 0.5 + 0.3}" width="{@height}" height="{$lyrTitleBox}" x="{ -(@height div 2 ) -  0.3}">
       
  1116 						<xsl:call-template name="display-name"/>
       
  1117 					</text>
       
  1118 				</xsl:with-param>
       
  1119 			</xsl:call-template>
       
  1120 		</xsl:if>
       
  1121 		<xsl:variable name="spans" select="following-sibling::layer[@span and position() - @span &lt;= 0]"/>
       
  1122 		<xsl:variable name="w" select="ancestor::SystemDefinition/@model-width -  sum($spans/@width) - $groupDx * count($spans)"/>
       
  1123 
       
  1124 		<xsl:variable name="x-off">
       
  1125 			<xsl:choose>
       
  1126 				<xsl:when test="$w &lt;= @width">0</xsl:when> <!-- should never be less than 0 -->
       
  1127 				<xsl:when test="@align='left'">0</xsl:when>
       
  1128 				<xsl:when test="@align='right'"><xsl:value-of select="$w - @width"/></xsl:when>
       
  1129 				<xsl:otherwise><xsl:value-of select="0.5 * ($w - @width)"/></xsl:otherwise> <!-- align='center' -->
       
  1130 			</xsl:choose>
       
  1131 		</xsl:variable>
       
  1132 		<g class="layer-detail" transform="translate({3.5 + $lyrTitleBox + $x-off} {sum(@ipad) *0.5})">
       
  1133 			<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'mouseover'"/></xsl:apply-templates>
       
  1134 			<rect x="{-$x-off}" class="{name()}" y="{-0.5 * sum(@ipad)}" width="{$w}" height="{@height}">
       
  1135 				<xsl:call-template name="styles"/>
       
  1136 				<xsl:if test="not($show-content)">
       
  1137 				 <xsl:attribute name="rx"><xsl:value-of select="$lyrTitleBox*0.5"/></xsl:attribute>
       
  1138 				 <xsl:attribute name="ry"><xsl:value-of select="$lyrTitleBox*0.5"/></xsl:attribute>
       
  1139 				 </xsl:if>
       
  1140 			</rect>
       
  1141 
       
  1142 			<xsl:variable name="overlay"><xsl:apply-templates select="." mode="overlay-styles"/></xsl:variable>
       
  1143 			<xsl:variable name="cur" select="."/>
       
  1144 			
       
  1145 			
       
  1146 			<xsl:for-each select="exslt:node-set($overlay)/*">
       
  1147 				<rect x="{-$x-off}" y="{-0.5 * sum($cur/@ipad)}" width="{$w}" height="{$cur/@height}"  style="{.}"/>
       
  1148 			</xsl:for-each>
       
  1149 
       
  1150 			<xsl:if test="not($show-content)">
       
  1151 				<xsl:call-template name="linkable-content">
       
  1152 					<xsl:with-param name="show">
       
  1153 						<text  text-anchor="middle" dy="0.375em" class="layer" 
       
  1154 							 y="{0.5 * @height}" width="{@width}" height="{@height}" x="{ 0.5 * @width}">
       
  1155 							<xsl:call-template name="display-name"/>
       
  1156 						</text>
       
  1157 					</xsl:with-param>
       
  1158 				</xsl:call-template>
       
  1159 			</xsl:if>
       
  1160 			<g><xsl:apply-templates select="." mode="detail-stuff"/>
       
  1161 				<xsl:apply-templates select="*"/>
       
  1162 			</g>		
       
  1163 		</g>
       
  1164 	</g>
       
  1165 </xsl:template>
       
  1166 
       
  1167 <!-- print levels for fixed or non-fixed width -->
       
  1168 <xsl:template match="layer/meta[@rel='model-levels' and ancestor::SystemDefinition[@levels='show' and @detail='layer']]">
       
  1169 	<xsl:for-each select="level[@name]">
       
  1170 		<text text-anchor="middle" class="level" x="{../../@width * 0.5}" width="{../../@width}" dy="0.375em">
       
  1171 			<xsl:attribute name="y">
       
  1172 				<xsl:choose>
       
  1173 					<xsl:when test="ancestor::SystemDefinition/@detail-type='fixed'">
       
  1174 						<xsl:value-of select="(count(following-sibling::level) + 0.5)* $mHeight * 1.5"/>
       
  1175 					</xsl:when>
       
  1176 					<xsl:otherwise>
       
  1177 						<xsl:value-of select="sum(following-sibling::level/@height) +count(following-sibling::level/@height) + 0.5* @height "/>
       
  1178 					</xsl:otherwise>
       
  1179 				</xsl:choose>
       
  1180 			</xsl:attribute>
       
  1181 			<xsl:call-template name="display-name"/>
       
  1182 		</text>
       
  1183 	</xsl:for-each>
       
  1184 </xsl:template>
       
  1185 
       
  1186 <xsl:template match="layer/meta[@rel='model-levels' and ancestor::SystemDefinition[@levels='expand']]">
       
  1187 	<xsl:variable name="spans" select="../following-sibling::layer[@span and position() - @span &lt;= 0]"/>
       
  1188 	<xsl:variable name="w" select="ancestor::SystemDefinition/@model-width -  sum($spans/@width) - $groupDx * count($spans)"/>
       
  1189 
       
  1190 	<xsl:for-each select="level[@name]">
       
  1191 		<xsl:variable name="y" select="sum(following-sibling::level/@height) + $groupDy * count(following-sibling::level) + 0.5 * @height"/>
       
  1192 		<text text-anchor="middle" class="level" x="{$w - $levelExpandName * 0.2 - ($w - ../../@width) * 0.5}" width="{@height}" y="{$y}" height="{$levelExpandName}" dy="0em" transform="rotate(-90 {$w - $levelExpandName * 0.2 - ($w - ../../@width) * 0.5} {$y})">
       
  1193 			<xsl:call-template name="display-name"/>
       
  1194 		</text>
       
  1195 	</xsl:for-each>
       
  1196 </xsl:template>
       
  1197 
       
  1198 
       
  1199 <xsl:template match="layer[@span &gt; 0]">
       
  1200 	<xsl:variable name="y" select="sum(@padding-top|following-sibling::layer[not(@span)]/@*[name()='height'  or name()='padding-bottom' or name()='padding-top']) + count(following::layer[not(@span)]) * $groupDy"/>
       
  1201 	
       
  1202 	<xsl:variable name="spans" select="following-sibling::layer[@span and position() - @span &lt;= 0]"/>
       
  1203 	<xsl:variable name="w" select="ancestor::SystemDefinition/@model-width -  sum($spans/@width) - $groupDx * count($spans)"/>
       
  1204     <xsl:variable name="show-content" select="not(ancestor::SystemDefinition[@detail='layer' and not(@levels='show')])"/> <!-- only show if showing content -->
       
  1205 	
       
  1206 	<xsl:variable name="x-off" select="$w - @width"/>
       
  1207 	<g class="{name()}" id="{@id}" transform="translate({$x-off + $groupDx} {$y})">
       
  1208 		<xsl:apply-templates select="." mode="filter"/>
       
  1209 		<g class="layer-detail" transform ="translate({$lyrTitleBox + 3.5} {sum(@ipad) *0.5})">
       
  1210 			<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'mouseover'"/></xsl:apply-templates>
       
  1211 			<rect x="0" class="{name()}" y="{-0.5 * sum(@ipad)}" width="{@width}" height="{@height}">
       
  1212 				<xsl:call-template name="styles"/>
       
  1213 				<xsl:if test="not($show-content)">
       
  1214 					 <xsl:attribute name="rx"><xsl:value-of select="$lyrTitleBox*0.5"/></xsl:attribute>
       
  1215 					 <xsl:attribute name="ry"><xsl:value-of select="$lyrTitleBox*0.5"/></xsl:attribute>
       
  1216 				 </xsl:if>				
       
  1217 			</rect>
       
  1218 
       
  1219 			<xsl:variable name="overlay"><xsl:apply-templates select="." mode="overlay-styles"/></xsl:variable>
       
  1220 			<xsl:variable name="cur" select="."/>
       
  1221 			<xsl:for-each select="exslt:node-set($overlay)/*">
       
  1222 				<rect x="0" width="{$cur/@width}" height="{$cur/@height}" y="{-0.5 * sum($cur/@ipad)}" style="{.}"/>
       
  1223 			</xsl:for-each>
       
  1224 
       
  1225 			<xsl:call-template name="linkable-content">
       
  1226 				<xsl:with-param name="show">
       
  1227 					<text text-anchor="middle" class="layer" width="{@width}" x="{@width div 2}">
       
  1228 						<xsl:attribute name="y">
       
  1229 							<xsl:choose>
       
  1230 								<xsl:when test="ancestor::SystemDefinition[@detail='layer']">
       
  1231 									<xsl:value-of select="@height * 0.5"/>
       
  1232 								</xsl:when>
       
  1233 								<xsl:otherwise>
       
  1234 									<xsl:value-of select="@height - $groupDy - 2.3"/>								
       
  1235 								</xsl:otherwise>
       
  1236 							</xsl:choose>
       
  1237 						</xsl:attribute>
       
  1238 						<xsl:if test="ancestor::SystemDefinition[@detail='layer']"> <!--  middle align if no content, otherwise text goes at bottom -->
       
  1239 							<xsl:attribute name="dy">0.375em</xsl:attribute>
       
  1240 							<xsl:copy-of select="@height"/>
       
  1241 						</xsl:if>
       
  1242 						<xsl:call-template name="display-name"/>
       
  1243 					</text>
       
  1244 				</xsl:with-param>
       
  1245 			</xsl:call-template>
       
  1246 			<g><xsl:apply-templates select="." mode="detail-stuff"/>					
       
  1247 				<xsl:apply-templates select="*"/>
       
  1248 			</g>
       
  1249 		</g>
       
  1250 	</g>
       
  1251 
       
  1252 </xsl:template>
       
  1253 
       
  1254 <xsl:template name="my-class">
       
  1255 	<xsl:attribute name="class">
       
  1256 		<xsl:value-of select="name()"/>
       
  1257 		<xsl:if test="not(*[not(self::meta)])"> placeholder</xsl:if>
       
  1258 		<xsl:if test="name()=name(..)"> nested</xsl:if>
       
  1259 	</xsl:attribute>	
       
  1260 </xsl:template>
       
  1261 
       
  1262 <!-- ====== packages  ============= -->
       
  1263 <xsl:template match="package">
       
  1264 
       
  1265 	<xsl:variable name="match" select="../meta[@rel='model-levels']/level[@name=current()/@level  or not(current()/@level)  or (current()/@span and following-sibling::level[position() &lt; current()/@span][@name=current()/@level or (not(@name) and current()/@level='*')]) or (current()/@level='*' and not(@name))]"/>
       
  1266 
       
  1267 	<xsl:variable name="h">
       
  1268 			<xsl:choose>
       
  1269 				<xsl:when test="$match"> <!-- get height from height of (spanned) levels -->
       
  1270 						<xsl:value-of select="sum($match/@height) + $groupDy * (count($match) - 1)"/>
       
  1271 				</xsl:when>
       
  1272 				<xsl:when test="parent::layer/@span or count(../package)!=1"> <!-- has siblings, so height of layer will do (- padding) -->
       
  1273 						<xsl:value-of select="../@height - sum(../@ipad)"/>
       
  1274 				</xsl:when>
       
  1275 				<xsl:otherwise><xsl:value-of select="@height"/></xsl:otherwise>
       
  1276 			</xsl:choose>
       
  1277 	</xsl:variable>  
       
  1278 
       
  1279 	<xsl:variable name="x">
       
  1280 		<xsl:choose>
       
  1281 			<xsl:when test="../meta[@rel='model-levels']/level/step[@ref=current()/@id]">
       
  1282 				<xsl:value-of select="../meta[@rel='model-levels']/level/step[@ref=current()/@id]/@x"/>
       
  1283 			</xsl:when>
       
  1284 			<xsl:otherwise><xsl:value-of select="sum(preceding-sibling::package/@width) + count(preceding-sibling::package) * $groupDx"/></xsl:otherwise>	
       
  1285 		</xsl:choose>
       
  1286 	</xsl:variable>
       
  1287 
       
  1288 		<xsl:variable name="lev" select="../meta[@rel='model-levels']/level[@name=current()/@level  or (current()/@level='*' and not(@name))]"/>
       
  1289 		<xsl:variable name="y" select="sum($lev/following-sibling::level/@height) + $groupDy * count($lev/following-sibling::level)"/>
       
  1290 		
       
  1291 	<xsl:variable name="translate-y">
       
  1292 		<xsl:choose>
       
  1293 			<xsl:when test="@levels or not(collection/@level)"><xsl:value-of select="$y"/></xsl:when>
       
  1294 			<xsl:otherwise>0</xsl:otherwise>
       
  1295 		</xsl:choose>
       
  1296 	</xsl:variable>
       
  1297 
       
  1298 	<g id="{@id}">
       
  1299 		<xsl:call-template name="my-class"/>
       
  1300 		<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'mouseover'"/></xsl:apply-templates>
       
  1301 		<xsl:apply-templates select="." mode="filter"/>	
       
  1302 		<xsl:attribute name="transform">translate( <xsl:value-of select="concat($x,' ',$translate-y)"/>)</xsl:attribute>
       
  1303 		<xsl:apply-templates select="." mode="animate-color"/>
       
  1304         <xsl:apply-templates select="." mode="multi-color"/>		
       
  1305 		<rect class="{name()}" x="0" width="{@width}" height="{$h}" y="{$y - $translate-y }">
       
  1306 			<xsl:call-template name="styles"/>
       
  1307 		</rect>		
       
  1308 		
       
  1309 		<xsl:variable name="overlay"><xsl:apply-templates select="." mode="overlay-styles"/></xsl:variable>
       
  1310 		<xsl:variable name="cur" select="."/>
       
  1311 		<xsl:for-each select="exslt:node-set($overlay)/*">
       
  1312 			<rect x="0" width="{$cur/@width}" height="{$h}" y="{$y - $translate-y }" style="{.}"/>
       
  1313 		</xsl:for-each>
       
  1314 		<xsl:variable name="middle" select="not(collection|package) or (ancestor::SystemDefinition[@detail='package' and not(@levels='show')] and not(package))"/>
       
  1315 		
       
  1316 		<xsl:variable name="text-off"> <!--  middle-align if not showing children -->
       
  1317 			<xsl:choose>
       
  1318 				<xsl:when test="$middle"><xsl:value-of select="$h *0.5"/></xsl:when>
       
  1319 				<xsl:otherwise>0</xsl:otherwise>
       
  1320 			</xsl:choose>
       
  1321 		</xsl:variable>
       
  1322 		<xsl:variable name="padding" select="sum(@ipad) + number($h - @height &gt; 2 * $groupDy)  * 2 * $groupDy * (1 - count(@ipad))"/>
       
  1323 			<!-- use @ipad or 2groupdy if h is significantly bigger then @height  -->
       
  1324 		<!-- label goes here -->
       
  1325 		<xsl:call-template name="linkable-content">
       
  1326 			<xsl:with-param name="show">
       
  1327 				<text text-anchor="middle" class="package" width="{@width}" x="{@width div 2}" y="{ $y + $h - $text-off   - $translate-y - 1 }">
       
  1328 					<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'text'"/></xsl:apply-templates>
       
  1329 						<!--  centre-align if not showing children -->				
       
  1330 					<xsl:if test="$middle">
       
  1331 							<xsl:attribute name="dy">0.375em</xsl:attribute>
       
  1332 							<xsl:attribute name="height"><xsl:value-of select="@height"/></xsl:attribute>
       
  1333 					</xsl:if>
       
  1334 					<xsl:variable name="txt"><xsl:call-template name="name-value"/></xsl:variable>
       
  1335 					<xsl:variable name="level-h" select="count(meta[@rel='model-levels']/level) *  ($mHeight + $groupDy) - $groupDy + $padding"/>  
       
  1336 					<xsl:choose>
       
  1337 						<!-- the $cSize * string-length($txt) * 0.25 assumes 4 chars per component-width is a good
       
  1338 							determinant of the amount of pkg text that can fit in a given width. This fails, of course, when
       
  1339 							the font or font size changes via CSS, something that can't be resolved here at all, however
       
  1340 							it's not a bad failsafe condition, since it just puts text where there is the most room for it
       
  1341 							It just might look funny if the font is smaller than expected and there'd be plenty of room for
       
  1342 							it at the bottom.
       
  1343 							The ".../level[1]/@width != 0 and count(...) &gt; 1" means that if the first level has nothing in it,
       
  1344 							then there's plenty of room and no need for an inline label  
       
  1345 							The ($h - $level-h &lt; $mHeight)" bit means the same thing, except it takes into account that the 
       
  1346 							levels might not go all the way to the bottom of the pkg							 
       
  1347 						-->
       
  1348 						<xsl:when test="package"/> <!-- can't be inline -->
       
  1349 						<xsl:when test="@width &lt; $cSize * string-length($txt) * 0.25 and meta[@rel='model-levels']/level[1]/@width != 0 and count(meta[@rel='model-levels']/level) &gt; 1 and ($h - $level-h &lt; $mHeight)">
       
  1350 							<xsl:variable name="min-width">
       
  1351 								<xsl:for-each select="meta[@rel='model-levels']/level">
       
  1352 									<xsl:sort select="@width" order="ascending" data-type="number"/>
       
  1353 									<xsl:if test="position()=1"><xsl:value-of select="@width"/></xsl:if>
       
  1354 								</xsl:for-each>
       
  1355 							</xsl:variable>
       
  1356 							<xsl:if test="$min-width  = @width or @width - $min-width &gt; $inlineLabel and string-length($txt) &gt; 12">
       
  1357 								<xsl:call-template name="inline-label">
       
  1358 									<xsl:with-param name="y0" select="$y  - $translate-y "/>
       
  1359 								</xsl:call-template>
       
  1360 							</xsl:if>
       
  1361 						</xsl:when>
       
  1362 						<xsl:when test="$pkgLabelSize  &lt;= $h - $level-h "/>  <!--  plenty of room on bottom, no need for inline label -->
       
  1363 						<xsl:when test="ancestor::SystemDefinition[@detail='collection' or @detail='component' or @detail='layer']">
       
  1364 							<xsl:call-template name="inline-label">
       
  1365 								<xsl:with-param name="y0" select="$y  - $translate-y "/>
       
  1366 							</xsl:call-template>
       
  1367 						</xsl:when>
       
  1368 					</xsl:choose>
       
  1369 					<xsl:call-template name="display-name"/>
       
  1370 				</text>
       
  1371 			</xsl:with-param>
       
  1372 		</xsl:call-template>
       
  1373 		
       
  1374 
       
  1375 
       
  1376 		<g>
       
  1377 			<xsl:if test="$padding !=0"><xsl:attribute name="transform">translate(0 <xsl:value-of select="0.5* $padding"/>)</xsl:attribute></xsl:if>
       
  1378 			<xsl:apply-templates select="." mode="detail-stuff"/>		
       
  1379 			<xsl:apply-templates select="*"/>	
       
  1380 		</g>
       
  1381 
       
  1382 	</g>
       
  1383 </xsl:template>
       
  1384 
       
  1385 <!-- print pkg levels if desired -->
       
  1386 <xsl:template match="package/meta[@rel='model-levels' and ancestor::SystemDefinition[@levels='show' and @detail='package']]" >
       
  1387 	<xsl:for-each select="level">
       
  1388 		<xsl:if test="@name">
       
  1389 			<text text-anchor="start" class="level" x="{$groupDx}" width="{../../@width - 2 * $groupDx}" y="{count(../../parent::package) *$groupDy + (last() - position()) * ($mHeight + $groupDy) }" dy="0.75em">
       
  1390 				<xsl:call-template name="display-name"/>
       
  1391 			</text>
       
  1392 		</xsl:if>
       
  1393 	</xsl:for-each>
       
  1394 </xsl:template>
       
  1395 
       
  1396 <xsl:template match="package/meta[@rel='model-levels' and ancestor::SystemDefinition[@levels='expand']]">
       
  1397 	<xsl:for-each select="level">
       
  1398 		<xsl:if test="@name">
       
  1399 			<xsl:variable name="y" select="count(../../parent::package) * $groupDy + (last() - position()) * ($mHeight + $groupDy) + 0.5 * $mHeight"/>
       
  1400 			<text text-anchor="middle" class="level" x="{../../@width - $levelExpandName * 0.2 }" width="{$mMinWidth}" height="{$levelExpandName}" y="{$y}" transform="rotate(-90 {../../@width - $levelExpandName * 0.2 } {$y})" dy="0em">
       
  1401 				<xsl:call-template name="display-name"/>
       
  1402 			</text>
       
  1403 		</xsl:if>
       
  1404 	</xsl:for-each>
       
  1405 </xsl:template>
       
  1406 
       
  1407 <xsl:template name="inline-label"><xsl:param name="y0"/>
       
  1408 	<xsl:variable name="thin-level">
       
  1409 		<xsl:for-each select="meta[@rel='model-levels']/level">
       
  1410 			<xsl:sort select="@width" order="ascending" data-type="number"/>
       
  1411 			<xsl:sort select="count(preceding-sibling::level)" order="ascending" data-type="number"/> <!-- to make sure it's at the lowest level if there is a choice -->
       
  1412 			<xsl:if test="position()=1"><xsl:value-of select="@name"/></xsl:if>
       
  1413 		</xsl:for-each>
       
  1414 	</xsl:variable>
       
  1415 	<xsl:variable name="lev" select="meta[@rel='model-levels']/level[@name=$thin-level or $thin-level='' and not(@name)]"/>
       
  1416 	<xsl:variable name="y" select="$y0 + count($lev/following-sibling::level) * ($mHeight +  $groupDy) + sum(@ipad) *0.5 "/>
       
  1417 	<xsl:attribute name="dy">0.375em</xsl:attribute>
       
  1418 	<xsl:attribute name="width"><xsl:value-of select="@width - $lev/@width"/></xsl:attribute>
       
  1419 	<xsl:attribute name="x"><xsl:value-of select="0.5 * (@width +  $lev/@width)"/></xsl:attribute> <!-- centre-aligned -->
       
  1420 	<xsl:attribute name="y"><xsl:value-of select="$y +  0.5 * $mHeight"/></xsl:attribute> <!-- middle-algined -->
       
  1421 </xsl:template>
       
  1422 
       
  1423 
       
  1424 
       
  1425 <!--- sub-packages -->
       
  1426 
       
  1427 <xsl:template match="package/package"  priority="2">
       
  1428 	<xsl:variable name="x">
       
  1429 		<xsl:call-template name="sum-list">
       
  1430 			<xsl:with-param name="list">
       
  1431 				<xsl:value-of select="sum(preceding-sibling::package/@width) + $groupDx * count(preceding-sibling::package)"/>
       
  1432 		<xsl:text> </xsl:text>
       
  1433 		<xsl:apply-templates mode="effective-width" select="preceding-sibling::collection[following-sibling::*[1][self::package]]">
       
  1434 			<xsl:with-param name="levels"><xsl:copy-of select="../meta[@rel='model-levels']/level"/></xsl:with-param>
       
  1435 		</xsl:apply-templates>
       
  1436 			</xsl:with-param>
       
  1437 		</xsl:call-template>
       
  1438 	</xsl:variable>
       
  1439 
       
  1440 	<g id="{@id}" transform="translate({$x})">
       
  1441 		<xsl:call-template name="my-class"/>
       
  1442 		<xsl:apply-templates select="." mode="filter"/>
       
  1443 		<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'mouseover'"/></xsl:apply-templates>		
       
  1444 		<xsl:apply-templates select="." mode="animate-color"/>
       
  1445         <xsl:apply-templates select="." mode="multi-color"/>		
       
  1446 		<rect class="{name()}" x="0" height="{@height}" width="{@width}" y ="0">
       
  1447 			<xsl:if test="not(collection) or ancestor::SystemDefinition/@detail=name()">
       
  1448 				<!-- to make room for the block label -->
       
  1449 				<xsl:attribute name="height"><xsl:value-of select="@height"/></xsl:attribute>
       
  1450 			</xsl:if>
       
  1451 			<xsl:call-template name="styles"/>
       
  1452 		</rect>
       
  1453 
       
  1454 
       
  1455 		<xsl:variable name="overlay"><xsl:apply-templates select="." mode="overlay-styles"/></xsl:variable>
       
  1456 		<xsl:variable name="cur" select="."/>
       
  1457 		<xsl:for-each select="exslt:node-set($overlay)/*">
       
  1458 			<rect x="0" height="{$cur/@height}" width="{$cur/@width}" y ="0" style="{.}">
       
  1459 				<xsl:if test="not($cur/collection) or $cur/ancestor::SystemDefinition/@detail=name($cur)">
       
  1460 					<!-- to make room for the block label -->
       
  1461 					<xsl:attribute name="height"><xsl:value-of select="$cur/@height"/></xsl:attribute>
       
  1462 				</xsl:if>
       
  1463 			</rect>
       
  1464 		</xsl:for-each>
       
  1465 		<xsl:call-template name="linkable-content">
       
  1466 			<xsl:with-param name="show">		
       
  1467 				<!-- default is for not showing detail, since it's easy to calculate -->
       
  1468 				<text text-anchor="middle" class="{name()}" dy="0.375em" x="{@width * 0.5}" width="{@width}" y="{0.5 * @height}">
       
  1469 					<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'text'"/></xsl:apply-templates>
       
  1470 						<xsl:if test="not(ancestor::SystemDefinition/@detail='package')">
       
  1471 							<xsl:call-template name="inline-label">
       
  1472 								<xsl:with-param name="y0" select="0"/>
       
  1473 							</xsl:call-template>
       
  1474 						</xsl:if>
       
  1475 					<xsl:call-template name="display-name"/>
       
  1476 				</text>
       
  1477 			</xsl:with-param>
       
  1478 		</xsl:call-template>
       
  1479 		<g><xsl:apply-templates select="." mode="detail-stuff"/>
       
  1480 			<xsl:apply-templates select="*"/>
       
  1481 		</g>	
       
  1482 	</g>
       
  1483 </xsl:template>
       
  1484 
       
  1485 
       
  1486 <!-- ====== collections  ============= -->
       
  1487 
       
  1488 <xsl:template match="collection">
       
  1489 <xsl:variable name="y" >
       
  1490 	<xsl:choose>
       
  1491 		<xsl:when test="ancestor::package/@levels or not(ancestor::layer/meta[@rel='model-levels'])">
       
  1492 			<!-- the positions come from the pkg only -->
       
  1493 			<xsl:value-of select="count(../meta[@rel='model-levels']/level[(current()[not(@level)] and not(@name)) or @name=current()/@level]/following-sibling::level) * ($mHeight +  $groupDy)"/> 
       
  1494 		</xsl:when>
       
  1495 		<xsl:otherwise>
       
  1496 			<!-- the positions come from the levels from the layer -->
       
  1497 			<xsl:variable name="lev" select="ancestor::layer/meta[@rel='model-levels']/level[(current()[not(@level)] and not(@name)) or @name=current()/@level]/following-sibling::level"/>
       
  1498 			<xsl:value-of select="sum($lev/@height) + $groupDy * count($lev)"/> 
       
  1499 		</xsl:otherwise>	
       
  1500 	</xsl:choose>
       
  1501 </xsl:variable>
       
  1502 
       
  1503 	<xsl:variable name="on-level" select="preceding-sibling::collection[(current()[not(@level)] and not(@level)) or @level=current()/@level]"/>
       
  1504 	
       
  1505 
       
  1506 <xsl:variable name="x">
       
  1507 	<xsl:choose>
       
  1508 		<xsl:when test="../package and not(preceding-sibling::package)">
       
  1509 			<!-- treat as if it's a normal collection-->
       
  1510 			<xsl:value-of  select="sum($on-level/@width) + $groupDx * count($on-level) "/>
       
  1511 		</xsl:when>
       
  1512 		<xsl:when test="../package">
       
  1513 			<xsl:call-template name="sum-list">
       
  1514 				<xsl:with-param name="list">	
       
  1515 					<xsl:value-of select="sum(preceding-sibling::package/@width) + $groupDx * count(preceding-sibling::package)"/>
       
  1516 					<xsl:text> </xsl:text>
       
  1517 					<xsl:apply-templates mode="effective-width" select="preceding-sibling::collection[following-sibling::*[1][self::package]]">
       
  1518 						<xsl:with-param name="levels"><xsl:apply-templates select=".." mode="levels"/></xsl:with-param>
       
  1519 					</xsl:apply-templates>
       
  1520 					<xsl:variable name="prev" select="preceding-sibling::collection[preceding-sibling::package[@id=current()/preceding-sibling::package[1]/@id]][@level = current()/@level or (not(@level) and not(current()/@level))]"/>
       
  1521 					<xsl:if test="$prev">
       
  1522 						<xsl:value-of select="concat(sum($prev/@width) + $groupDx * count($prev), ' ')"/>
       
  1523 					</xsl:if>
       
  1524 				</xsl:with-param>
       
  1525 			</xsl:call-template>
       
  1526 		</xsl:when>
       
  1527 		<xsl:otherwise>
       
  1528 		<xsl:value-of  select="sum($on-level/@width) + $groupDx * count($on-level) "/>
       
  1529 		</xsl:otherwise>
       
  1530 	</xsl:choose>
       
  1531 	</xsl:variable>
       
  1532 	
       
  1533 	
       
  1534 	<g id="{@id}" transform="translate({$x} {$y})"><xsl:apply-templates select="." mode="filter"/>
       
  1535 		<xsl:call-template name="my-class"/>
       
  1536 		<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'mouseover'"/></xsl:apply-templates>
       
  1537 		<xsl:apply-templates select="." mode="animate-color"/>
       
  1538         <xsl:apply-templates select="." mode="multi-color"/>
       
  1539 		<rect class="{name()}" x="0" y="0" height="{@height}" width="{@width}">
       
  1540 			<xsl:call-template name="styles"/>
       
  1541 		</rect>
       
  1542 		<xsl:variable name="overlay"><xsl:apply-templates select="." mode="overlay-styles"/></xsl:variable>
       
  1543 		<xsl:variable name="cur" select="."/>
       
  1544 		<xsl:for-each select="exslt:node-set($overlay)/*">
       
  1545 			<rect width="{$cur/@width}" height="{$cur/@height}" x="0" y="0" style="{.}"/>
       
  1546 		</xsl:for-each>
       
  1547 		
       
  1548 		
       
  1549 		
       
  1550 		<xsl:call-template name="linkable-content">
       
  1551 			<xsl:with-param name="show">
       
  1552 			<!-- dy=1em means top align, but leave a bit of space up there so the top of the text is not flush against the border
       
  1553 				The alternative would be set y to a fixed offset (like the 1.4 x-offset) and use dy="0.75em" to make the text be
       
  1554 				flush against this offset, but I suspect the 1em method will look better in a wider variety of fonts--> 
       
  1555 				<text  text-anchor="start" dy="1em" class="collection" y="0" x="1.4" width="{@width - 1.4}">
       
  1556 					<xsl:apply-templates select="." mode="detail-stuff"><xsl:with-param name="s" select="'text'"/></xsl:apply-templates>
       
  1557 					<xsl:choose>
       
  1558 						<xsl:when test="not(component) or ancestor::SystemDefinition/@detail='collection' ">
       
  1559 							<xsl:attribute name='text-anchor'>middle</xsl:attribute>
       
  1560 							<xsl:attribute name='x'><xsl:value-of select="@width * 0.5"/></xsl:attribute>
       
  1561 							<xsl:attribute name='dy'>0.375em</xsl:attribute> <!-- middle align if no content -->
       
  1562 							<xsl:attribute name="y"><xsl:value-of select="@height * 0.5"/></xsl:attribute>
       
  1563 							<xsl:attribute name="height"><xsl:value-of select="@height"/></xsl:attribute>
       
  1564 						</xsl:when>
       
  1565 						<xsl:otherwise>
       
  1566 							<xsl:attribute name="height"><xsl:value-of select="@height - component/@height"/></xsl:attribute> <!--all children are the same size -->
       
  1567 						</xsl:otherwise>
       
  1568 					</xsl:choose>
       
  1569 					<xsl:call-template name="display-name"/>
       
  1570 				</text>
       
  1571 			</xsl:with-param>
       
  1572 		</xsl:call-template>
       
  1573 		<g transform="translate(0 {@height - $cSize})">
       
  1574 			<xsl:apply-templates select="." mode="detail-stuff"/>
       
  1575 			<xsl:apply-templates select="*"/>
       
  1576 		</g>		
       
  1577 	</g>
       
  1578 </xsl:template>
       
  1579 
       
  1580 
       
  1581 <!-- ====== components  ============= -->
       
  1582 
       
  1583 <xsl:template match="component|cmp">
       
  1584 	<xsl:param name="spacing" select="0"/>
       
  1585 	<!-- the bulk of the following is for cmp, not component -->
       
  1586 	<xsl:variable name="x-pos">
       
  1587 		<xsl:choose>
       
  1588 			<xsl:when test="self::cmp">
       
  1589 				<xsl:value-of select="sum(preceding-sibling::*/@width | preceding-sibling::*/@rpad | ../@label-width) "/>
       
  1590 			</xsl:when>
       
  1591 			<xsl:otherwise>
       
  1592 				<xsl:value-of select="sum(preceding-sibling::component/@width) "/>
       
  1593 			</xsl:otherwise>
       
  1594 		</xsl:choose>
       
  1595 	</xsl:variable>
       
  1596 	<g id="{@id}">
       
  1597 		<xsl:call-template name="my-class"/>
       
  1598 		<xsl:apply-templates select="." mode="filter"/>
       
  1599 		<xsl:if test="parent::collection">
       
  1600 			<xsl:apply-templates select="." mode="animate-color"/>
       
  1601 	        <xsl:apply-templates select="." mode="multi-color"/>			
       
  1602 		</xsl:if>
       
  1603 		<xsl:variable name="ref"><xsl:apply-templates select="." mode="shape"/></xsl:variable>
       
  1604 		<use width="{@width}" height="{@height}" x="{$x-pos}" y="0" xlink:href="{$ref}">
       
  1605 			<xsl:variable name="style"><xsl:apply-templates select="." mode="display-style"/></xsl:variable>
       
  1606 			<xsl:if test="string-length($style) &gt; 1">
       
  1607 				<xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute>
       
  1608 			</xsl:if>
       
  1609 		</use>
       
  1610 		<xsl:variable name="overlay"><xsl:apply-templates select="." mode="overlay-styles"/></xsl:variable>
       
  1611 		<xsl:variable name="cur" select="."/>
       
  1612 		<xsl:for-each select="exslt:node-set($overlay)/*">
       
  1613 			<use width="{$cur/@width}" height="{$cur/@height}" x="{$x-pos}" y="0" style="{.}" xlink:href="{$ref}"/>
       
  1614 		</xsl:for-each>
       
  1615 		<xsl:call-template name="linkable-content">
       
  1616 			<xsl:with-param name="show">
       
  1617 				<text text-anchor="middle" dy="0.375em"  class="component" y="{@height * 0.5 + 0.15}" width="{@width}" height="{@height}" x="{$x-pos + 0.5 * @width}">
       
  1618 					<xsl:call-template name="display-name"/>
       
  1619 				</text>
       
  1620 			</xsl:with-param>
       
  1621 		</xsl:call-template>
       
  1622 	</g>
       
  1623 </xsl:template>
       
  1624 
       
  1625 
       
  1626 <!-- ============ Detail options============ -->
       
  1627 
       
  1628 <!-- don't show when not enough detail -->
       
  1629 <xsl:template match="component[not(ancestor::SystemDefinition[@detail='component' or not(@static='true' or @detail-type='fixed')]) ]" priority="9"/>
       
  1630 <xsl:template match="collection[  ancestor::SystemDefinition[(@detail='layer' or @detail='package') and (@static='true'  or @detail-type='fixed')] 	]" priority="9"/>
       
  1631 <xsl:template match="package[ancestor::SystemDefinition[@detail='layer'  and (@static='true'  or @detail-type='fixed')] ]" priority="9"/>
       
  1632 
       
  1633 <xsl:template match="*[ancestor::SystemDefinition/@detail='component']" mode="detail-stuff" priority="9"/>
       
  1634 <xsl:template match="*" mode="detail-stuff" priority="-5"/>
       
  1635 
       
  1636 <xsl:template match="*[ancestor::SystemDefinition/@static='true']" mode="detail-stuff" priority="7"/>
       
  1637 <xsl:template match="*[ancestor::SystemDefinition/@detail-type='fixed']" mode="detail-stuff" priority="8"/>
       
  1638 
       
  1639 <xsl:template match="collection[ancestor::SystemDefinition/@detail!='collection'] | *[(ancestor::SystemDefinition/@detail='collection') and not(self::collection)]" mode="detail-stuff" priority="5"/>
       
  1640 
       
  1641 <xsl:template match="collection|package[ancestor::SystemDefinition/@detail='package' and not(package)] | layer[ancestor::SystemDefinition/@detail=name()]" mode="detail-stuff">
       
  1642 	<xsl:param name="s" select="'content'"/>
       
  1643 	<xsl:choose>
       
  1644 		<xsl:when test="$s='mouseover'">
       
  1645 			<xsl:attribute name="onmouseover">on('<xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/>');off('<xsl:value-of select="name()"/>-label-<xsl:value-of select="@id"/>');</xsl:attribute>
       
  1646 			<xsl:attribute name="onmouseout">off('<xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/>');on('<xsl:value-of select="name()"/>-label-<xsl:value-of select="@id"/>');</xsl:attribute>
       
  1647 		</xsl:when>
       
  1648 		<xsl:when test="$s='text'">
       
  1649 			<xsl:attribute name="id"><xsl:value-of select="name()"/>-label-<xsl:value-of select="@id"/></xsl:attribute>
       
  1650 		</xsl:when>
       
  1651 		<xsl:otherwise>
       
  1652 			<xsl:attribute name="id"><xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/></xsl:attribute>
       
  1653 			<xsl:attribute name="visibility">hidden</xsl:attribute>
       
  1654 		</xsl:otherwise>
       
  1655 	</xsl:choose>
       
  1656 </xsl:template>
       
  1657 
       
  1658 <xsl:template priority="8" match="package[package and ancestor::SystemDefinition/@detail='package']/collection" mode="detail-stuff"><xsl:param name="s" select="'content'"/>
       
  1659 	<xsl:if test="$s='mouseover'">
       
  1660 		<xsl:attribute name="id"><xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/></xsl:attribute>
       
  1661 		<xsl:attribute name="visibility">hidden</xsl:attribute>
       
  1662 	</xsl:if>
       
  1663 </xsl:template>
       
  1664 
       
  1665 
       
  1666 <xsl:template match="layer[ancestor::SystemDefinition/@detail=name() or not(package)]" mode="detail-stuff"><xsl:param name="s" select="'content'"/>
       
  1667 	<xsl:choose>
       
  1668 		<xsl:when test="$s='mouseover'">
       
  1669 			<xsl:attribute name="onmouseover">on('<xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/>')</xsl:attribute>
       
  1670 			<xsl:attribute name="onmouseout">off('<xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/>')</xsl:attribute>
       
  1671 		</xsl:when>
       
  1672 		<xsl:when test="$s!='text'">
       
  1673 			<xsl:attribute name="id"><xsl:value-of select="name()"/>-content-<xsl:value-of select="@id"/></xsl:attribute>
       
  1674 			<xsl:attribute name="visibility">hidden</xsl:attribute>
       
  1675 		</xsl:when>
       
  1676 	</xsl:choose>
       
  1677 </xsl:template>
       
  1678 <xsl:template match="*[ancestor::systemModel/@detail='layer' and not(self::layer)]" mode="detail-stuff"/>
       
  1679 
       
  1680 
       
  1681 <xsl:template name="navctrl">	
       
  1682  <g id="Zoom" onload="resized()">
       
  1683  <set attributeType="CSS" attributeName="opacity"  to="0.8"  fill="freeze" begin="Zoom.mouseover"/>
       
  1684  <set attributeType="CSS" attributeName="opacity"  to="0.8"  fill="freeze" begin="Zoomin.mouseover"/>
       
  1685  <set attributeType="CSS" attributeName="opacity"  to="0.8"  fill="freeze" begin="Zoomout.mouseover"/>
       
  1686   <animate attributeType="CSS" attributeName="opacity" from="0.8" to="0" fill="freeze" dur="0.5s" begin="10s"/>
       
  1687   <animate attributeType="CSS" attributeName="opacity"  from="0.8" to="0"  fill="freeze" dur="0.2s" begin="Zoom.mouseout" />
       
  1688   <animate attributeType="CSS" attributeName="opacity"  from="0.8" to="1"  fill="freeze" dur="0.5s" begin="0.3s" />
       
  1689 
       
  1690  <path d="M0,0 l15,0 l0,30 a 7.5,7.5 18 0,1 -15, 0Z" fill="rgb(0,102,153)" opacity="0.8"/>
       
  1691  <g onclick="zoom(1.25)">
       
  1692  	<path d="M7.5,4.5 l0,3 m1.5,-1.5 l-3,0" stroke="yellow" stroke-width="1" pointer-events="none" />
       
  1693  	<circle id="Zoomin" r="4.5" cx="7.5" cy="6" fill="url(#Patternoutgrad)">
       
  1694  		<set attributeType="XML" attributeName="fill" to="url(#Patterningrad)" fill="freeze" begin="Zoomin.mouseover" />
       
  1695  		<set attributeType="XML" attributeName="fill" to="url(#Patternoutgrad)" fill="freeze" begin="Zoomin.mouseout" />
       
  1696  	</circle>
       
  1697  </g>
       
  1698  <g onclick="zoom(0.8)">
       
  1699  	<path d="M5.5,18 l4,0" stroke="yellow" stroke-width="1" pointer-events="none" />
       
  1700  	<circle r="4.5" cx="7.5" cy="18" fill="url(#Patternoutgrad)" id="Zoomout">
       
  1701  		<set attributeType="XML" attributeName="fill" to="url(#Patterningrad)" fill="freeze" begin="Zoomout.mouseover" />
       
  1702  		<set attributeType="XML" attributeName="fill" to="url(#Patternoutgrad)" fill="freeze" begin="Zoomout.mouseout" />
       
  1703  	</circle>
       
  1704  </g>
       
  1705  <path id="MoveUp" d="M7.5,25  l1.5,3 l-3,0 Z" fill-opacity="0.2" stroke-opacity="0.7" stroke-linejoin="round" fill="white" stroke="white" stroke-width="0.4" onmousedown="repeatpan(0,20)" onmouseup="endpanning()">
       
  1706  		<set attributeType="XML" attributeName="stroke" to="yellow" end="MoveUp.mouseout" begin="MoveUp.mouseover" />
       
  1707  	</path>
       
  1708  	<path id="MoveDown" d="M6,33  l3,0 l-1.5,3 Z" fill-opacity="0.2" stroke-linejoin="round" stroke-opacity="0.7" fill="white" stroke="white" stroke-width="0.4" onmousedown="repeatpan(0,-20)" onmouseup="endpanning()">
       
  1709  		<set attributeType="XML" attributeName="stroke" to="yellow" end="MoveDown.mouseout" begin="MoveDown.mouseover" />
       
  1710  	</path>
       
  1711  	<path id="MoveRight" d="M10,29  l3,1.5 l-3,1.5 Z" fill-opacity="0.2" stroke-linejoin="round" stroke-opacity="0.7" fill="white" stroke="white" stroke-width="0.4" onmousedown="repeatpan(-20,0)" onmouseup="endpanning()">
       
  1712  		<set attributeType="XML" attributeName="stroke" to="yellow" end="MoveRight.mouseout" begin="MoveRight.mouseover" />
       
  1713  	</path>
       
  1714  	<path id="MoveLeft" d="M5,29  l0,3 l-3,-1.5 Z" fill-opacity="0.2" stroke-linejoin="round" stroke-opacity="0.7" fill="white" stroke="white" stroke-width="0.4" onmousedown="repeatpan(20,0)" onmouseup="endpanning()">
       
  1715  		<set attributeType="XML" attributeName="stroke" to="yellow" end="MoveLeft.mouseout" begin="MoveLeft.mouseover" />
       
  1716  	</path>
       
  1717  	</g>
       
  1718 </xsl:template>
       
  1719 
       
  1720 
       
  1721 <xsl:include href="draw-model.xsl"/>
       
  1722 </xsl:stylesheet>