sysmodellibs/sysmodelgen/src/old/svg/Shapes.xsl
changeset 6 5b32dc297d05
parent 1 b538b70cbe51
equal deleted inserted replaced
3:e7e0ae78773e 6:5b32dc297d05
       
     1 <?xml version="1.0"?>
       
     2  <xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:a="http://www.w3.org/1999/XSL/Transform-" version="1.0" xmlns:s="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:exslt="http://exslt.org/common" xmlns:doc="tooldoc">
       
     3   	<xsl:output method="xml" indent="yes"/>
       
     4 	<xsl:param name="Model-Transform" select="'model.xsl'"/> <!-- the location of the model.xsl relative to where the *output* of this transform is stored-->
       
     5 	<xsl:param name="Verbose" select="0"/> <!-- Verbosity level of messages. Set to 1 (or higher) to get runtime comments  -->
       
     6 	<xsl:namespace-alias stylesheet-prefix="a" result-prefix="xsl"/>
       
     7 
       
     8 <xsl:variable name="color" select="/model/layout/info[@type='color']"/>
       
     9 <xsl:variable name="borders" select="/model/layout/info[@type='border']"/>
       
    10 <xsl:variable name="overlay" select="/model/layout/info[@type='overlay']"/>
       
    11 <xsl:variable name="style" select="/model/layout/info[@type='style']"/>
       
    12 
       
    13 <xsl:template match="/model"> 
       
    14 	<a:stylesheet version="1.0" exclude-result-prefixes="doc s exslt">
       
    15 		<xsl:for-each select="document(@shapes)/shapes/namespace::*"><xsl:copy-of select="."/></xsl:for-each>
       
    16 		<a:include href="{$Model-Transform}"/>
       
    17 		<xsl:apply-templates select="document(@shapes,.)/*"/>
       
    18 
       
    19 		<!--  this is a bit redundant:  i think it's only necessary for the cmp. Either that or it can be used for the component, and the stuff to 
       
    20 			make the defaults for all components should be removed from model.xsl -->
       
    21 		<xsl:if test="$borders"> <!-- if there are borders defined in the model.xml, use those to shape the cmp borders, not the shapes.xml -->
       
    22 			<!-- default border -->	
       
    23 			<xsl:for-each select="document($borders/@href,$borders)/values/@default">
       
    24 				<!-- if the default is a type, create the actual reference. If it's a reference leave it alone -->
       
    25 				<a:template match="component[not(@generator-border)]|cmp[not(@generator-border)]" mode="shape">
       
    26 					<xsl:if test="not(starts-with(.,'#'))">#Border</xsl:if>
       
    27 					<xsl:value-of select="."/>
       
    28 				</a:template>
       
    29 			</xsl:for-each>
       
    30 		</xsl:if>
       
    31 
       
    32 		<xsl:if test="$overlay"> <!-- if there are patterns defined in the model.xml, use those to shape the cmp overlays, not the shapes.xml -->
       
    33 			<!-- default overlay (usually there will be no default))-->	
       
    34 			<xsl:for-each select="document($overlay/@href,$overlay)/values/@default">
       
    35 				<!-- if the default is a type, create the actual reference. If it's a reference leave it alone -->
       
    36 				<a:template match="component[not(@generator-overlay)]|cmp[not(@generator-overlay)]" mode="shape">
       
    37 					<xsl:if test="not(starts-with(.,'#'))">#Pattern</xsl:if>
       
    38 					<xsl:value-of select="."/>
       
    39 				</a:template>
       
    40 			</xsl:for-each>
       
    41 		</xsl:if>
       
    42 
       
    43 		<xsl:if test="$color">
       
    44 			<xsl:for-each select="document($color/@href,$color)/values/@default">
       
    45 				<a:template match="component[not(@generator-color|generator-color)] | cmp[not(@generator-color|generator-color)]" mode="display-style-color">
       
    46 					<xsl:value-of select="."/>
       
    47 				</a:template>
       
    48 			</xsl:for-each>
       
    49 		</xsl:if>
       
    50 		
       
    51 		<!-- values files with styles override any styles in the shapes file
       
    52 			Also if there are no styles in the shapes file, don't try to look for them -->
       
    53 		<xsl:if test="not(document(@shapes)/shapes/styles) or layout/info[@type='style' and @href]">
       
    54 			<a:template match="component" mode="display-style-aux"/> <!-- no more default styles -->
       
    55 		</xsl:if>
       
    56 		
       
    57 		<xsl:if test="not(document(@shapes)/shapes/patterns)">
       
    58 		<a:template match="component|cmp" mode="overlay-style" priority="-1">fill: none; stroke: none; stroke-width: 0;</a:template>
       
    59 			 <!-- no rule-based patterns -->
       
    60 		</xsl:if>
       
    61 		
       
    62 	
       
    63 	<a:template match="SystemDefinition" mode="shapes">
       
    64 		<xsl:variable name="defs" select="s:defs"/> <!-- all defs in the shapes document -->
       
    65 		<!-- check the overlay docs for all referred IDs. Make a list of all that are not defined the shapes doc -->
       
    66 		<xsl:variable name="undefinedP">
       
    67 			<xsl:for-each select="document($overlay/@href)/*">
       
    68 				<xsl:for-each select="@default | //item/@value">
       
    69 					<xsl:value-of select="concat(' ',.,' ')"/>
       
    70 				</xsl:for-each>
       
    71 			</xsl:for-each>
       
    72 			<xsl:for-each select="document(@shapes)/shapes/patterns/overlay[@type]">
       
    73 					<xsl:value-of select="concat(' ',@type,' ')"/>
       
    74 			</xsl:for-each>
       
    75 		</xsl:variable>
       
    76 		<!-- check the borders docs for all referred IDs. Make a list of all that are not defined the shapes doc -->
       
    77 		<xsl:variable name="undefinedB">
       
    78 			<xsl:for-each select="document($borders/@href)/*">
       
    79 				<xsl:for-each select="@default | //item/@value">
       
    80 					<xsl:value-of select="concat(' ',.,' ')"/>
       
    81 				</xsl:for-each>
       
    82 			</xsl:for-each>
       
    83 			<xsl:for-each select="document(@shapes)/shapes/borders/border/@type">
       
    84 					<xsl:value-of select="concat(' ',.,' ')"/>
       
    85 			</xsl:for-each>
       
    86 		</xsl:variable>	
       
    87 
       
    88 	<!-- ignore all patterns not defined: should make a warning eventually. 
       
    89 		Also nice to check to see if any ref'd ID's  (eg #xxx) are defined -->
       
    90 		
       
    91 		 <!-- no 'reference' pattern defined, so use the default one --> 
       
    92 		<xsl:if test="contains($undefinedP,' radial-grad ')"><a:call-template name="default-new-pattern"/></xsl:if>
       
    93 		 <!-- no 'new'  pattern defined, so use the default one --> 
       
    94 		<xsl:if test="contains($undefinedP,' striped-diag-up ')"><a:call-template name="default-ref-pattern"/></xsl:if>
       
    95 		 <!-- no 'deprecated'  pattern defined, so use the default one --> 
       
    96 		 <xsl:if test="contains($undefinedP,' big-X ')"><a:call-template name="default-X-pattern"/></xsl:if>
       
    97 
       
    98 		 <!-- borders defined --> 
       
    99 		 <!--  if no borders were defined at all, throw in the default ones -->
       
   100 		<xsl:if test="contains($undefinedB,' box ') or normalize-space($undefinedB)=''"><a:call-template name="default-box-border"/></xsl:if>
       
   101 		<xsl:if test="contains($undefinedB,' box-clipLB ') or normalize-space($undefinedB)=''"><a:call-template name="default-clipLB-border"/></xsl:if>
       
   102 		<xsl:if test="contains($undefinedB,' box-clipLT ') or normalize-space($undefinedB)=''"><a:call-template name="default-clipLT-border"/></xsl:if>
       
   103 		<xsl:if test="contains($undefinedB,' box-clipRB ') or normalize-space($undefinedB)=''"><a:call-template name="default-clipRB-border"/></xsl:if>
       
   104 		<xsl:if test="contains($undefinedB,' box-clipRT ') or normalize-space($undefinedB)=''"><a:call-template name="default-clipRT-border"/></xsl:if>
       
   105 		<xsl:if test="contains($undefinedB,' box-clipAll ') or normalize-space($undefinedB)=''"><a:call-template name="default-clipAll-border"/></xsl:if>
       
   106 		<xsl:if test="contains($undefinedB,' round ')"><a:call-template name="default-round-border"/></xsl:if>
       
   107 		<xsl:if test="contains($undefinedB,' hexagon ')"><a:call-template name="default-hexagon-border"/></xsl:if>
       
   108 
       
   109 		<xsl:for-each select="document(@shapes)/shapes">
       
   110 			<xsl:copy-of select="s:defs/*"/>
       
   111 			<xsl:apply-templates select="borders|colors[@type!='background']|patterns" mode="defines"/>
       
   112 		</xsl:for-each>
       
   113 
       
   114 		
       
   115 	</a:template>
       
   116 	
       
   117 	<a:template match="*[@label-ref]" mode="eval-label">
       
   118 	<!-- next two lines are hacks to ensure this works if called accidently from a node-set or wrong file-->
       
   119 		<a:if test="not(/*/systemModel) and @label"><a:value-of select="@label"/></a:if>
       
   120 		<a:if test="not(/*/systemModel) and not(@label)"><a:value-of select="."/></a:if>
       
   121 		<a:variable name="id" select="@label-ref"/>
       
   122 		<xsl:variable name="abbrevs" select="document(/model/layout/info/@href,/)/display-names//abbrev"/> <!-- the abbreviations list -->
       
   123 		<a:for-each select="/*/systemModel">
       
   124 			<a:choose>
       
   125 				<xsl:apply-templates mode="make-label-eval" select="//legend[contains(@label,'}') and not(@literal='yes' or @literal='true')]">
       
   126 					<xsl:with-param name="abbrevs" select="$abbrevs"/>
       
   127 				</xsl:apply-templates>
       
   128 				<xsl:apply-templates mode="make-label-eval" select="//note[contains(.,'}') and not(@literal='yes' or @literal='true')]">
       
   129 					<xsl:with-param name="abbrevs" select="$abbrevs"/>
       
   130 				</xsl:apply-templates>
       
   131 				<xsl:for-each select="document(layout/info/@href | @shapes,.)">
       
   132 					<xsl:apply-templates mode="make-label-eval" select="//*[contains(@label,'}') and not(@literal='yes' or @literal='true')]">
       
   133 						<xsl:with-param name="abbrevs" select="$abbrevs"/>
       
   134 					</xsl:apply-templates>
       
   135 					<xsl:apply-templates mode="make-label-eval" select="/shapes/examples/cmp[contains(text(),'}') and not(@literal='yes' or @literal='true')]">
       
   136 						<xsl:with-param name="abbrevs" select="$abbrevs"/>
       
   137 					</xsl:apply-templates>
       
   138 				</xsl:for-each>
       
   139 			</a:choose>
       
   140 		</a:for-each>
       
   141 	</a:template>
       
   142 	</a:stylesheet>
       
   143 </xsl:template>
       
   144 
       
   145 
       
   146 <xsl:template mode="make-label-eval" match="*"><xsl:param name="abbrevs"/>
       
   147 	<a:when>
       
   148 		<xsl:attribute name="test">$id='<xsl:apply-templates select="." mode="style-id"/>'</xsl:attribute>
       
   149 		<xsl:call-template name="computed-label">
       
   150 			<xsl:with-param name="text">
       
   151 				<xsl:call-template name="local-label"><xsl:with-param name="abbrevs" select="$abbrevs"/></xsl:call-template>
       
   152 			</xsl:with-param>
       
   153 		</xsl:call-template>
       
   154 	</a:when>
       
   155 </xsl:template> 
       
   156 
       
   157 <xsl:template name="local-label"><xsl:param name="abbrevs"/>
       
   158 	<xsl:variable name="val">
       
   159 		<xsl:value-of select="@label"/>
       
   160 		<xsl:if test="not(@label) and (self::cmp or self::note)"><xsl:value-of select="text()"/></xsl:if>
       
   161 	</xsl:variable>
       
   162 	<xsl:variable name="match" select="$abbrevs[@name=$val]"/>
       
   163 	<xsl:choose>
       
   164 		<xsl:when test="$match"><xsl:value-of select="$match/@abbrev"/></xsl:when>
       
   165 		<xsl:otherwise><xsl:value-of select="$val"/></xsl:otherwise>
       
   166 	</xsl:choose>
       
   167 </xsl:template>
       
   168 
       
   169 
       
   170 <xsl:template name="computed-label">	<xsl:param name="text" select="@label"/>
       
   171 	<xsl:choose>
       
   172 		<xsl:when test="contains($text,'{')">
       
   173 			<a:text><xsl:value-of select="substring-before($text,'{')"/></a:text>
       
   174 			<xsl:variable name="eval" select="substring-before(substring-after($text,'{'),'}')"/>
       
   175 			<xsl:choose>
       
   176 				<xsl:when test="starts-with($eval,'@') and string-length($eval)=string-length(translate($eval,'=/ *()[]','')) "> <!-- if this passes, then this will generally just be an attribute -->
       
   177 					<a:apply-templates select="{$eval}" mode="as-text"/>
       
   178 				</xsl:when>
       
   179 				<xsl:otherwise><a:value-of select="{$eval}"/></xsl:otherwise>
       
   180 			</xsl:choose>
       
   181 			<xsl:call-template name="computed-label">
       
   182 				<xsl:with-param name="text" select="substring-after(substring-after($text,'{'),'}')"/>
       
   183 			</xsl:call-template>
       
   184 		</xsl:when>
       
   185 		<xsl:when test="$text!=''"><a:text><xsl:value-of select="$text"/></a:text></xsl:when>
       
   186 	</xsl:choose>
       
   187 </xsl:template>
       
   188 
       
   189 <xsl:template match="/shapes">
       
   190 	<xsl:comment>Shapes</xsl:comment>
       
   191 	<xsl:for-each select="styles|colors|patterns|borders">
       
   192 		<xsl:if test="@use or not(*)">
       
   193 			<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>	
       
   194 		  <a:key name="{name()}-{$id}" match="group[@style-id='{$id}']/*" use="@lookup"/>
       
   195 		  	<xsl:choose>
       
   196 				<xsl:when test="@use">
       
   197 				  <a:key name="use-{$id}" >
       
   198 				  	<xsl:copy-of select=" @use"/>
       
   199 				  	<xsl:call-template name="match-syntax"/>
       
   200 				  </a:key>
       
   201 				</xsl:when>
       
   202 				<xsl:when test="self::colors[@match='@ts']">
       
   203 					<a:key name="use-{$id}" match="component" use="@ts"/>
       
   204 				</xsl:when>
       
   205 			</xsl:choose>
       
   206 		</xsl:if>
       
   207 	</xsl:for-each>
       
   208 
       
   209 	<xsl:if test="not($borders)"> <!-- borders must be defined in the shapes.xml -->
       
   210 		<xsl:apply-templates select="borders"/>
       
   211 	</xsl:if>
       
   212 
       
   213 	<xsl:choose> <!-- only background colours can be defined in $color -->
       
   214 		<xsl:when test="not($color)">
       
   215 			<xsl:apply-templates select="colors"/>
       
   216 		</xsl:when>
       
   217 		<xsl:otherwise>
       
   218 			<xsl:apply-templates select="colors[@type and @type!='background']"/>
       
   219 		</xsl:otherwise>
       
   220 	</xsl:choose>
       
   221 
       
   222 	<xsl:if test="not($overlay)">
       
   223 		<xsl:apply-templates select="patterns"/>
       
   224 	</xsl:if>
       
   225 
       
   226 
       
   227 <!-- concatenate all default styles for legend items -->
       
   228   <a:template match="cmp[not(@generated-style) and not(generated-style)]" mode="display-style-aux">
       
   229 		<xsl:for-each select="styles/style[not(@rule|@value)]"><xsl:value-of select="."/>;</xsl:for-each>    
       
   230   </a:template>
       
   231 
       
   232 <!-- create style attribute in the general case-->
       
   233 <a:template match="*" mode="display-style-aux">
       
   234 	<xsl:for-each select="styles">
       
   235 		<a:apply-templates select="." mode="display-style-{position()}"/>
       
   236 	</xsl:for-each>
       
   237 </a:template>
       
   238 
       
   239 	<!--  default to nothing for each style. This will be overriden later if necesssary -->
       
   240 	<xsl:for-each select="styles">
       
   241 		<a:template match="*" mode="display-style-{position()}"/>
       
   242 	</xsl:for-each>
       
   243 	
       
   244 	<xsl:apply-templates select="styles"/>
       
   245 	
       
   246 	<!-- only needed for options with rule. Options with lookup values are checked elsewhere -->
       
   247 	<xsl:for-each select="(borders|styles|patterns|colors)[not(@show-unused='yes') and */@rule]">
       
   248 		<a:template> <!-- default match is component -->
       
   249 			<xsl:call-template name="match-syntax"/>
       
   250 			<xsl:attribute name="mode">show-unused-<xsl:value-of select="concat(name(),@type)"/>
       
   251 				<xsl:if test="self::colors[not(@type)]">background</xsl:if></xsl:attribute>
       
   252 				<a:param name="n"/>
       
   253 				<xsl:call-template name="declare-vars"/>
       
   254 			<a:choose>
       
   255 				<xsl:for-each select="*[@rule]">
       
   256 					<a:when>
       
   257 						<xsl:attribute name="test"><xsl:apply-templates select="." mode="when-test"/></xsl:attribute>
       
   258 						<a:if>
       
   259 							<xsl:attribute name="test">$n='<xsl:apply-templates select="." mode="style-id"/>'</xsl:attribute>
       
   260 							<xsl:text>*</xsl:text>
       
   261 						</a:if>
       
   262 					</a:when>
       
   263 				</xsl:for-each>
       
   264 				<xsl:for-each select="*[not(@rule|@value)]">
       
   265 					<a:when>
       
   266 						<xsl:attribute name="test">$n='<xsl:apply-templates select="." mode="style-id"/>'</xsl:attribute>
       
   267 						<xsl:text>*</xsl:text>
       
   268 					</a:when>
       
   269 				</xsl:for-each>
       
   270 			</a:choose>
       
   271 		</a:template>
       
   272 	</xsl:for-each>
       
   273 	
       
   274 </xsl:template>
       
   275 
       
   276 <!-- remove all quoted parens -->
       
   277 <xsl:template name="replace-quotes"><xsl:param name="text" select="."/>
       
   278 	<xsl:choose>
       
   279 		<xsl:when test="contains($text,'&quot;')">
       
   280 			<xsl:value-of select="substring-before($text,'&quot;')"/>
       
   281 			<xsl:text> </xsl:text>
       
   282 			<xsl:value-of select="translate(substring-before(substring-after($text,'&quot;'),'&quot;'),'()','  ')"/>
       
   283 			<xsl:text> </xsl:text>
       
   284 			<xsl:call-template name="replace-quotes">
       
   285 				<xsl:with-param name="text" select="substring-after(substring-after($text,'&quot;'),'&quot;')"/>
       
   286 			</xsl:call-template>			
       
   287 		</xsl:when>
       
   288 		<xsl:when test='contains($text,"&apos;")'>
       
   289 			<xsl:value-of select='substring-before($text,"&apos;")'/>
       
   290 			<xsl:text> </xsl:text>
       
   291 			<xsl:value-of select='translate(substring-before(substring-after($text,"&apos;"),"&apos;"),"()","  ")'/>
       
   292 			<xsl:text> </xsl:text>
       
   293 			<xsl:call-template name="replace-quotes">
       
   294 				<xsl:with-param name="text" select='substring-after(substring-after($text,"&apos;"),"&apos;")'/>
       
   295 			</xsl:call-template>			
       
   296 		</xsl:when>
       
   297 		<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
       
   298 	</xsl:choose>
       
   299 </xsl:template>
       
   300 
       
   301 <xsl:template name="param-length"><xsl:param name="text"/>
       
   302 <xsl:variable name="close-idx"  select="string-length(substring-before($text,')'))"/>
       
   303 <xsl:choose>
       
   304 	<xsl:when test="not(contains($text,')'))"><xsl:message terminate="yes">badly-formatted funtion: <xsl:value-of select="$text"/></xsl:message></xsl:when>
       
   305 	<xsl:when test="contains($text,'(')">
       
   306 		<xsl:variable name="open-idx"  select="string-length(substring-before($text,'('))"/>	
       
   307 		<xsl:choose>
       
   308 			<xsl:when test="$close-idx &lt; $open-idx"><xsl:value-of select="$close-idx"/></xsl:when>
       
   309 			<xsl:otherwise>
       
   310 				<xsl:variable name="len">
       
   311 					<xsl:call-template name="param-length">
       
   312 						<xsl:with-param name="text" select="substring($text,2+$open-idx)"/>
       
   313 					</xsl:call-template>
       
   314 				</xsl:variable>
       
   315 				<xsl:value-of select="2 + $open-idx + $len"/>
       
   316 			</xsl:otherwise>
       
   317 		</xsl:choose>
       
   318 	</xsl:when>
       
   319 	<xsl:otherwise><xsl:value-of select="$close-idx"/></xsl:otherwise>
       
   320 </xsl:choose>
       
   321 </xsl:template>
       
   322 
       
   323 
       
   324 <xsl:template name="replace-function"><xsl:param name="text" select="."/>
       
   325 	<xsl:param name="function" select="'VERSION'"/>
       
   326 	<xsl:param name="before">string-length(substring-before(concat(' ',$Versions,' '),(</xsl:param>
       
   327 	<xsl:param name="after">)))</xsl:param>
       
   328 	<xsl:param name="default">/SystemDefinition/systemModel/@ver</xsl:param>
       
   329 	<xsl:variable name="func" select="concat($function,'(')"/>
       
   330 	<xsl:variable name="t">
       
   331 		<xsl:call-template name="replace-quotes">
       
   332 			<xsl:with-param name="text" select="$text"/>
       
   333 		</xsl:call-template>
       
   334 	</xsl:variable>
       
   335 	<xsl:choose>
       
   336 		<xsl:when test="contains($t,$func)">
       
   337 			<xsl:value-of select="substring($text,1,string-length(substring-before($t,$func)))"/>
       
   338 			<xsl:variable name="pre" select="1 + string-length($func) + string-length(substring-before($t,$func))"/>
       
   339 			<xsl:variable name="a" select="substring($t,$pre)"/>
       
   340 			<xsl:variable name="r" select="substring($text,$pre)"/>
       
   341 			<xsl:variable name="len">
       
   342 				<xsl:call-template name="param-length">
       
   343 					<xsl:with-param name="text" select="$a"/>
       
   344 				</xsl:call-template>
       
   345 			</xsl:variable>
       
   346 				<xsl:variable name="arg" select="substring($r,1,$len)"/>
       
   347 				<xsl:value-of select="$before"/>
       
   348 				<xsl:choose>
       
   349 					<xsl:when test="normalize-space($arg)=''"><xsl:value-of select="$default"/></xsl:when>
       
   350 					<xsl:otherwise><xsl:value-of select="$arg"/></xsl:otherwise>
       
   351 				</xsl:choose>
       
   352 				<xsl:value-of select="$after"/>
       
   353 				<xsl:call-template name="replace-function">
       
   354 					<xsl:with-param name="text" select="substring($r,$len+2)"/>
       
   355 					<xsl:with-param name="function" select="$function"/>
       
   356 					<xsl:with-param name="before" select="$before"/>
       
   357 					<xsl:with-param name="default" select="$default"/>
       
   358 					<xsl:with-param name="after" select="$after"/>
       
   359 				</xsl:call-template>
       
   360 		</xsl:when>	
       
   361 		<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>		
       
   362 	</xsl:choose>
       
   363 </xsl:template>
       
   364 
       
   365 <xsl:template match="*[@rule]" mode="varname"><xsl:value-of select="name()"/>-var-<xsl:value-of select="count(preceding::*[@variable])"/></xsl:template>
       
   366 <xsl:template match="*/@rule"><xsl:param name="text" select="."/>
       
   367 	<xsl:variable name="fixed0">
       
   368 		<xsl:call-template name="replace-function">
       
   369 			<xsl:with-param name="text" select="$text"/>
       
   370 		</xsl:call-template>
       
   371 	</xsl:variable>
       
   372 	<xsl:variable name="fixed1">
       
   373 		<xsl:call-template name="replace-function">
       
   374 			<xsl:with-param name="text" select="$fixed0"/>
       
   375 			<xsl:with-param name="function">CLASS</xsl:with-param>
       
   376 			<xsl:with-param name="before">contains(concat(' ',normalize-space(@class),' '),concat(' ',</xsl:with-param>
       
   377 			<xsl:with-param name="default">1</xsl:with-param>
       
   378 			<xsl:with-param name="after">,' '))</xsl:with-param>
       
   379 		</xsl:call-template>
       
   380 	</xsl:variable>
       
   381 	<xsl:variable name="fixed">
       
   382 		<xsl:call-template name="replace-function">
       
   383 			<xsl:with-param name="text" select="$fixed1"/>
       
   384 			<xsl:with-param name="function">VARIABLE</xsl:with-param>
       
   385 			<xsl:with-param name="before"></xsl:with-param>
       
   386 			<xsl:with-param name="default">$<xsl:apply-templates select=".." mode="varname"/></xsl:with-param>
       
   387 			<xsl:with-param name="after"></xsl:with-param>
       
   388 		</xsl:call-template>
       
   389 	</xsl:variable>
       
   390 	<!--  this next bit is deprecated: remove soon -->
       
   391 	<xsl:choose>
       
   392 		<xsl:when test="contains($fixed,'$variable')">
       
   393 			<xsl:value-of select="substring-before($fixed,'$variable')"/>$<xsl:apply-templates select=".." mode="varname"/>
       
   394 			<xsl:apply-templates select="."><xsl:with-param name="text" select="substring-after($fixed,'$variable')"/></xsl:apply-templates>
       
   395 		</xsl:when>
       
   396 		<xsl:otherwise><xsl:value-of select="$fixed"/></xsl:otherwise>
       
   397 	</xsl:choose>
       
   398 </xsl:template>
       
   399 
       
   400 <!--=========== basic SVG definitions ==============-->
       
   401 
       
   402 
       
   403 <xsl:template match="color" mode="id">
       
   404 	<xsl:value-of select="concat(../@type,count(preceding::color[../@type]))"/>
       
   405 </xsl:template>
       
   406 
       
   407 <xsl:template match="overlay" mode="id">Pattern<xsl:choose>
       
   408 		<xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
       
   409 		<xsl:otherwise>Overlay<xsl:value-of select="count(preceding::overlay)"/></xsl:otherwise>
       
   410 	</xsl:choose>
       
   411 </xsl:template>
       
   412 
       
   413 <xsl:template match="border" mode="id">Border<xsl:choose>
       
   414 		<xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
       
   415 		<xsl:otherwise>Shape<xsl:value-of select="count(preceding::border)"/></xsl:otherwise>
       
   416 	</xsl:choose>
       
   417 </xsl:template>
       
   418 
       
   419 <!-- can explictly reference self-defined pattern or border: chop off starting #  -->
       
   420 <xsl:template match="*[starts-with(@type,'#')]" mode="id" priority="1"><xsl:value-of select="substring(@type,2)"/></xsl:template>
       
   421 
       
   422 
       
   423 <xsl:template match="border[@value] | color[@value] | overlay[@value] | style[@value]" mode="when-test">
       
   424 	<xsl:if test="not(../@use)">.</xsl:if>
       
   425 	<xsl:value-of select="../@use"/>='<xsl:value-of select="@value"/>'</xsl:template>
       
   426 
       
   427 <xsl:template match="border[@rule] |color[@rule] | overlay [@rule]  | style[@rule]" mode="when-test">
       
   428 	<xsl:variable name="rule"><xsl:apply-templates select="@rule"/></xsl:variable>
       
   429 	<xsl:choose>
       
   430 		<xsl:when test="../@use">(<xsl:value-of select="../@use"/>)[<xsl:value-of select="$rule"/>]</xsl:when>
       
   431 		<xsl:otherwise><xsl:value-of select="$rule"/></xsl:otherwise>
       
   432 	</xsl:choose>
       
   433 </xsl:template>
       
   434 
       
   435 
       
   436 <xsl:template match="borders" mode="defines">
       
   437 	<!-- make symbols for all the (unique) borders -->
       
   438 	<xsl:for-each select="border">
       
   439 		<xsl:if test="not(@type)">
       
   440 			<symbol>
       
   441 				<xsl:attribute name="id"><xsl:apply-templates select="." mode="id"/></xsl:attribute>
       
   442 				<xsl:apply-templates select="." mode="model"/>
       
   443 			</symbol>
       
   444 		</xsl:if>
       
   445 	</xsl:for-each>
       
   446 	
       
   447 	<xsl:if test="$Verbose">
       
   448 		<xsl:if test="not(border[not(@value|@rule)])"><xsl:message>&#xa;warning: no default border</xsl:message></xsl:if>
       
   449 		<xsl:if test="count(border[not(@value|@rule)]) &gt; 1 "><xsl:message>&#xa;error: more than one default border</xsl:message></xsl:if>
       
   450 	</xsl:if>	
       
   451 </xsl:template>
       
   452 
       
   453 
       
   454 <xsl:template match="patterns" mode="defines">
       
   455 	<!-- make symbols for all the (unique) overlays -->
       
   456  	<xsl:for-each select="*"> 	
       
   457 		<xsl:if test="count(self::overlay/*) &gt; 1 "><xsl:message>&#xa;error: more than one pattern in overlay</xsl:message></xsl:if>
       
   458 		<xsl:for-each select="self::*[not(@type)]/*[1]"> <!--  should only be one -->
       
   459 			<xsl:copy><xsl:copy-of select="@*"/>
       
   460 				<xsl:attribute name="id"><xsl:apply-templates select=".." mode="id"/></xsl:attribute>
       
   461 				<xsl:copy-of select="*"/>
       
   462 			</xsl:copy>
       
   463 		</xsl:for-each>
       
   464 	</xsl:for-each>
       
   465 	
       
   466 
       
   467 	<xsl:if test="count(*[not(@value|@rule)]) &gt; 1 "><xsl:message>&#xa;error: more than one default <xsl:value-of select="name(*)"/></xsl:message></xsl:if>
       
   468 
       
   469 </xsl:template>
       
   470 
       
   471 
       
   472 <xsl:template match="border" mode="model">
       
   473 	<xsl:copy-of select="@viewBox|*"/>
       
   474 </xsl:template>
       
   475 
       
   476 <!-- Borders -->
       
   477 <xsl:template match="borders">
       
   478 		<!-- add attributes to s:use element -->
       
   479 		<a:template mode="shape" match="component">
       
   480 			<!-- <xsl:call-template name="match-syntax"/> only applies to components -->
       
   481 			<xsl:call-template name="declare-vars"/>
       
   482 			<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>	
       
   483 			<xsl:choose>
       
   484 				<xsl:when test="@use and not(border[@rule])">
       
   485 					<!-- no borders with rules, should all be default or value -->
       
   486 				      <a:variable name="c" select="key('{name()}-{$id}',{@use})/@value"/>
       
   487 				  	  <a:value-of select="$c"/>
       
   488 			         <a:if test="not($c)">#<xsl:apply-templates select="border[not(@value)][1]" mode="id"/></a:if>					
       
   489 				</xsl:when>
       
   490 				<xsl:when test="border[@rule]">
       
   491 					<!-- at least one border has a rule -->
       
   492 					<a:choose>
       
   493 						<xsl:for-each select="border[@rule]">
       
   494 							<a:when>
       
   495 								<xsl:attribute name="test"><xsl:apply-templates select="." mode="when-test"/></xsl:attribute>
       
   496 								<xsl:text>#</xsl:text>
       
   497 								<xsl:apply-templates select="." mode="id"/>
       
   498 							</a:when>
       
   499 						</xsl:for-each>
       
   500 						<a:otherwise>
       
   501 							<xsl:choose>
       
   502 								<xsl:when test="@use">
       
   503 						      			<a:variable name="c" select="key('{name()}-{$id}',{@use})/@value"/>
       
   504 						  	  		<a:value-of select="$c"/>
       
   505 					         				<a:if test="not($c)">#<xsl:apply-templates select="border[not(@value)][1]" mode="id"/></a:if>
       
   506 					         			</xsl:when>
       
   507 					         			<xsl:when test="border[not(@value)]">#<xsl:apply-templates select="border[not(@value)][1]" mode="id"/></xsl:when>
       
   508 					         		</xsl:choose>
       
   509 						</a:otherwise>
       
   510 					</a:choose> 
       
   511 				</xsl:when>
       
   512 					<!-- no rules and no @use, must just have a single default -->
       
   513 				<xsl:when test="border[not(@value)]">#<xsl:apply-templates select="border[not(@value)][1]" mode="id"/></xsl:when>
       
   514 			</xsl:choose>
       
   515 		</a:template>			
       
   516 		<xsl:if test="border[not(@value)]">
       
   517 			<a:template match="cmp" mode="shape">
       
   518 				<xsl:text>#</xsl:text><xsl:apply-templates select="border[not(@value)][1]" mode="id"/>
       
   519 			</a:template>
       
   520 		</xsl:if>
       
   521 </xsl:template>
       
   522 
       
   523 
       
   524 <!-- Colours -->
       
   525 
       
   526 
       
   527 <xsl:template match="colors[@type='highlight']" mode="defines">
       
   528 	<xsl:for-each select="color">
       
   529 		<xsl:variable name="id"><xsl:apply-templates select="." mode="id"/></xsl:variable>
       
   530 		<filter id="{$id}" filterUnits="userSpaceOnUse">
       
   531 	  		<feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>
       
   532 	  		<feFlood flood-color="{@color}" flood-opacity="1" result="flood"/>
       
   533 			<feComposite in2="blur" in="flood" operator="atop" result="comp" />
       
   534 	  		<feMerge>    
       
   535 	  	  		<feMergeNode in="comp"/><feMergeNode in="SourceGraphic"/>
       
   536 	  		</feMerge>
       
   537 		</filter>
       
   538 	</xsl:for-each>
       
   539 </xsl:template>
       
   540 
       
   541 <xsl:template match="colors[@type='text-highlight']" mode="defines">
       
   542 	<xsl:for-each select="color">
       
   543 		<xsl:variable name="id"><xsl:apply-templates select="." mode="id"/></xsl:variable>
       
   544 		<filter id="{$id}" filterUnits="userSpaceOnUse">
       
   545 			<feMorphology operator="dilate" in="SourceAlpha" radius="0.2" result="blur"/>
       
   546 		 	<!-- <feGaussianBlur in="SourceAlpha" stdDeviation="0.8" result="blur"/> -->
       
   547 			<feFlood flood-color="{@color}" flood-opacity="1" result="flood"/>
       
   548 			<feComposite in2="blur" in="flood" operator="atop" result="comp" />
       
   549 			<feMerge><feMergeNode in="comp"/><feMergeNode in="SourceGraphic"/></feMerge>	
       
   550 		</filter>
       
   551 	</xsl:for-each>
       
   552 </xsl:template>
       
   553 
       
   554 
       
   555 <xsl:template match="colors">
       
   556 	<a:template mode="{substring-before(@type,'highlight')}filter">
       
   557 		<xsl:call-template name="match-syntax"/>
       
   558 		<xsl:call-template name="declare-vars"/>	
       
   559 		<a:choose>
       
   560 		<xsl:for-each select="color[@value|@rule]">
       
   561 			<a:when>
       
   562 				<xsl:attribute name="test"><xsl:apply-templates select="." mode="when-test"/></xsl:attribute>			
       
   563 				<a:attribute name="filter">url(#<xsl:apply-templates select="." mode="id"/>)</a:attribute>
       
   564 			</a:when>
       
   565 		</xsl:for-each>
       
   566 		<xsl:for-each select="color[not(@value|@rule)]">
       
   567 				<a:otherwise><a:attribute name="filter">url(#<xsl:apply-templates select="." mode="id"/>)</a:attribute></a:otherwise>
       
   568 		</xsl:for-each>
       
   569 		</a:choose>
       
   570 	</a:template>		
       
   571 </xsl:template>
       
   572 
       
   573 <xsl:template name="color-select">
       
   574   <xsl:param name="default"/>
       
   575   <xsl:param name="use" select="@use"/>
       
   576   <xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>  
       
   577   <a:variable name="c" select="key('{name()}-{$id}',{$use})/@value"/>
       
   578   <a:choose>
       
   579     <a:when test="not($c)"><xsl:value-of select="$default"/></a:when>
       
   580     <a:when test="count($c)=1"><a:value-of select="$c"/></a:when>
       
   581     <a:otherwise>url(#bg<a:apply-templates select="." mode="id"/>)</a:otherwise>
       
   582   </a:choose>
       
   583 </xsl:template>
       
   584 
       
   585 <xsl:template match="colors[@type='background' or not(@type)]" priority="1">
       
   586 	<xsl:variable name="default-color">
       
   587 		<xsl:choose>
       
   588 			<xsl:when test="color[not(@value|@rule)]"><xsl:value-of select="color[not(@value|@rule)]/@color"/></xsl:when>
       
   589 			<xsl:otherwise><xsl:value-of select="@default"/></xsl:otherwise>
       
   590 		</xsl:choose>
       
   591 	</xsl:variable>
       
   592 
       
   593 <!--  possible future enhancements: 
       
   594 	computed colour: expression to generate a comma-separated rgb tripple to be put inside "rgb(...)"  -->
       
   595 	
       
   596     <xsl:if test="@use or (not(*) and @match='@ts')">
       
   597 <!--    multiple colours: if there are multiple match they'll appear as a gradient-->
       
   598 	<a:template mode="multi-color">
       
   599     	<xsl:call-template name="match-syntax"/>
       
   600 			<xsl:variable name="key"><xsl:value-of select="name()"/>-<xsl:apply-templates select="." mode="style-id"/></xsl:variable>
       
   601 			<xsl:variable name="use">
       
   602 				<xsl:choose>
       
   603 					<xsl:when test="not(*) and @match='@ts'"><!-- ts hack -->
       
   604 						<xsl:value-of select="@match" />
       
   605 					</xsl:when>
       
   606 					<xsl:otherwise><xsl:value-of select="@use"/></xsl:otherwise>
       
   607 	 			</xsl:choose>
       
   608 			</xsl:variable>
       
   609 			<a:call-template name="multi-color-grad">
       
   610 			<xsl:choose>
       
   611 				<xsl:when test="@spacing='proportional'"> <!-- as opposed to the default: fixed -->
       
   612 					<a:with-param name="c" select="key('{$key}',{$use})/@value"/>
       
   613           		</xsl:when>
       
   614 				<xsl:otherwise>          		
       
   615 					<a:with-param name="key" select="'{$key}'"/>
       
   616 					<a:with-param name="c" select="{$use}"/>
       
   617 				</xsl:otherwise>
       
   618 			</xsl:choose>
       
   619           	<a:with-param name="dir" select="'{@direction}'" /> <!--  not documented! only used for XSLT processors that can't handle sin / cos -->
       
   620           	<a:with-param name="angle" select="'{@angle}'" />
       
   621           	<a:with-param name="blur">
       
   622           		<xsl:attribute name="select">
       
   623           			<xsl:choose>
       
   624           				<xsl:when test="not(@blur)">0</xsl:when>
       
   625           				<xsl:otherwise>
       
   626           					<xsl:value-of select="0.5 * 100 * @blur"/>
       
   627           				</xsl:otherwise>
       
   628           			</xsl:choose>
       
   629           		</xsl:attribute>
       
   630           	</a:with-param>
       
   631           </a:call-template>
       
   632     </a:template>
       
   633     </xsl:if>
       
   634 
       
   635 	<a:template mode="display-style-color">
       
   636 		<xsl:call-template name="match-syntax"/>
       
   637 		<xsl:call-template name="declare-vars"/>	
       
   638 		<xsl:choose>
       
   639 			<xsl:when test="@use and not(color[@rule])">
       
   640                   <xsl:call-template name="color-select">
       
   641                     <xsl:with-param name="default" select="$default-color"/>
       
   642                   </xsl:call-template>
       
   643 			</xsl:when>
       
   644 			<xsl:when test="not(*) and @match='@ts'">
       
   645                   <xsl:call-template name="color-select">
       
   646                     <xsl:with-param name="default" select="$default-color"/>
       
   647                     <xsl:with-param name="use" select="@match"/>
       
   648                   </xsl:call-template>
       
   649 			</xsl:when>
       
   650 			<xsl:otherwise>
       
   651 				<a:choose>
       
   652 					<xsl:for-each select="color[@rule]">
       
   653 						<a:when>
       
   654 							<xsl:attribute name="test"><xsl:apply-templates select="." mode="when-test"/></xsl:attribute>
       
   655 							<xsl:value-of select="@color"/>
       
   656 						</a:when>
       
   657 					</xsl:for-each>
       
   658 					<a:otherwise>
       
   659 						<xsl:choose>
       
   660 							<xsl:when test="@use"> <!-- only useful if there's something to look up -->
       
   661                                 <xsl:call-template name="color-select">
       
   662                                   <xsl:with-param name="default" select="$default-color"/>
       
   663                                 </xsl:call-template>
       
   664 					        </xsl:when>
       
   665 					        <xsl:otherwise>
       
   666 					        	<xsl:value-of select="$default-color"/>
       
   667 					        </xsl:otherwise>
       
   668 					       </xsl:choose>
       
   669 					</a:otherwise>
       
   670 				</a:choose> 
       
   671 			</xsl:otherwise>
       
   672 		</xsl:choose>
       
   673 	</a:template>
       
   674 	
       
   675 	<xsl:if test="(@type='background' or not(@type)) and $default-color!=''">
       
   676 		<a:template match="cmp" mode="display-style-color">
       
   677 			<xsl:value-of select="$default-color"/>
       
   678 		</a:template>
       
   679 	</xsl:if>
       
   680 	
       
   681 
       
   682 
       
   683 	<a:template mode="animate-color">
       
   684 		<xsl:call-template name="match-syntax"/>
       
   685 		<a:if test="not($Static)">
       
   686 		<xsl:call-template name="declare-vars"/>	
       
   687 		<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>	
       
   688 		<xsl:choose>
       
   689 			<xsl:when test="@use and not(color[@rule])">
       
   690 				<a:for-each select="key('{name()}-{$id}',{@use})">
       
   691 					<set attributeName="opacity" attributeType="XML" to="0.5" fill="remove">
       
   692 						<xsl:attribute name="begin">{@style-id}.mouseover</xsl:attribute>
       
   693 						<xsl:attribute name="end">{@style-id}.mouseout</xsl:attribute>
       
   694 					</set>
       
   695 				</a:for-each>			
       
   696 			</xsl:when>
       
   697 			<xsl:when test="not(*) and @match='@ts'">
       
   698 				<a:for-each select="key('{name()}-{$id}',@ts)">
       
   699 					<set attributeName="opacity" attributeType="XML" to="0.5" fill="remove">
       
   700 						<xsl:attribute name="begin">{@style-id}.mouseover</xsl:attribute>
       
   701 						<xsl:attribute name="end">{@style-id}.mouseout</xsl:attribute>
       
   702 					</set>
       
   703 				</a:for-each>			
       
   704 			</xsl:when>
       
   705 			<xsl:otherwise>
       
   706 				<a:choose>
       
   707 					<xsl:for-each select="color[@rule]">
       
   708 						<a:when>
       
   709 							<xsl:attribute name="test"><xsl:apply-templates select="." mode="when-test"/></xsl:attribute>
       
   710 								<set attributeName="opacity" attributeType="XML" to="0.5" fill="remove">
       
   711 									<xsl:attribute name="begin"><xsl:apply-templates select="." mode="style-id"/>.mouseover</xsl:attribute>
       
   712 									<xsl:attribute name="end"><xsl:apply-templates select="." mode="style-id"/>.mouseout</xsl:attribute>
       
   713 								</set>
       
   714 						</a:when>
       
   715 					</xsl:for-each>
       
   716 					<xsl:if test="@use"> <!-- only useful if there's something to look up -->
       
   717 						<a:otherwise>
       
   718 							<a:for-each select="key('{name()}-{$id}',{@use})">
       
   719 								<set attributeName="opacity" attributeType="XML" to="0.5" fill="remove">
       
   720 									<xsl:attribute name="begin">{@style-id}.mouseover</xsl:attribute>
       
   721 									<xsl:attribute name="end">{@style-id}.mouseout</xsl:attribute>
       
   722 								</set>
       
   723 							</a:for-each>		
       
   724 						</a:otherwise>
       
   725 					</xsl:if>						
       
   726 				</a:choose> 
       
   727 			</xsl:otherwise>
       
   728 		</xsl:choose>
       
   729 	</a:if>	
       
   730 	</a:template>
       
   731 		
       
   732 		
       
   733 </xsl:template>
       
   734 
       
   735 
       
   736 <xsl:template match="patterns">
       
   737 	<a:template mode="overlay-style">
       
   738 	 	<xsl:call-template name="match-syntax"/>
       
   739 		<xsl:call-template name="declare-vars"/>	
       
   740 		<a:variable name="fill">
       
   741 			<a:choose>
       
   742 				<xsl:for-each select="overlay">
       
   743 					<a:when>
       
   744 						<xsl:attribute name="test">
       
   745 							<xsl:apply-templates select="." mode="when-test"/>
       
   746 						</xsl:attribute>url(#<xsl:apply-templates mode="id" select="."/>)</a:when>
       
   747 				</xsl:for-each>
       
   748 			</a:choose>
       
   749 		</a:variable>
       
   750 
       
   751 		<a:if test="$fill !='' ">
       
   752 			<a:text>fill:</a:text>
       
   753 			<a:value-of select="$fill"/>
       
   754 			<a:text>; stroke: none; stroke-width: 0;</a:text>
       
   755 		</a:if>
       
   756 	</a:template>
       
   757 </xsl:template>
       
   758 
       
   759 <xsl:template name="declare-vars">
       
   760 	<xsl:for-each select="*[@variable]">
       
   761 		<a:variable>
       
   762 			<xsl:attribute name="name"><xsl:apply-templates select="." mode="varname"/></xsl:attribute>
       
   763 			<xsl:attribute name="select"><xsl:value-of select="@variable"/></xsl:attribute>
       
   764 		</a:variable>
       
   765 	</xsl:for-each>
       
   766 </xsl:template>
       
   767 
       
   768 <xsl:template match="styles">
       
   769 	<a:template mode="display-style-{position()}">
       
   770 	  	<xsl:call-template name="match-syntax"/>
       
   771 		<!--  set any necessary variables -->
       
   772 		<xsl:call-template name="declare-vars"/>
       
   773 		<a:choose>
       
   774 			<xsl:for-each select="style[@rule]">
       
   775 				<a:when>
       
   776 					<xsl:attribute name="test"><xsl:apply-templates select="." mode="when-test"/></xsl:attribute>				
       
   777 					<xsl:value-of select="."/>
       
   778 				</a:when>
       
   779 			</xsl:for-each>
       
   780 			<xsl:for-each select="style[not(@rule|value)]"> <!--  the default is last (if it exists)-->
       
   781 				<a:otherwise><xsl:value-of select="."/></a:otherwise>
       
   782 			</xsl:for-each>
       
   783 		</a:choose>
       
   784 		<a:text>; </a:text>
       
   785 </a:template>
       
   786 
       
   787 </xsl:template>
       
   788 
       
   789 <xsl:template name="match-syntax">
       
   790 	<xsl:choose>
       
   791 			<xsl:when test="not(@match) or @match='@ts'"><xsl:attribute name="match">component</xsl:attribute></xsl:when>
       
   792 			<xsl:when test="@match='module'"><xsl:attribute name="match">collection</xsl:attribute></xsl:when>
       
   793 			<xsl:when test="@match='logicalset'"><xsl:attribute name="match">block</xsl:attribute></xsl:when>
       
   794 			<xsl:when test="@match='logicalsubset'"><xsl:attribute name="match">subblock</xsl:attribute></xsl:when>
       
   795 			<xsl:otherwise><xsl:copy-of select="@match"/></xsl:otherwise>
       
   796 	</xsl:choose>
       
   797 </xsl:template>
       
   798 
       
   799 <!--  from model.xsl:  -->
       
   800 
       
   801 <xsl:template match="*" mode="style-id">
       
   802 <xsl:message>not found</xsl:message>
       
   803 </xsl:template>
       
   804 
       
   805 
       
   806 <xsl:template match="info" mode="style-id">
       
   807 	<xsl:value-of select="concat('i',count(preceding-sibling::info))"/>
       
   808 </xsl:template>
       
   809 
       
   810 <xsl:template match="legend" mode="style-id">
       
   811 	<xsl:value-of select="concat('L',count(preceding::legend))"/>
       
   812 </xsl:template>
       
   813 
       
   814 <xsl:template match="note" mode="style-id">
       
   815 	<xsl:value-of select="concat('n',count(preceding::note))"/>
       
   816 </xsl:template>
       
   817 	
       
   818 <!-- what about values and items? -->
       
   819 
       
   820 <xsl:template match="colors|borders|patterns|styles|examples" mode="style-id">
       
   821 	<xsl:value-of select="concat('s',count(preceding-sibling::*))"/>
       
   822 </xsl:template>
       
   823 
       
   824 <xsl:template match="colors/color|borders/border|patterns/overlay|styles/style" mode="style-id">
       
   825 	<xsl:apply-templates select=".." mode="style-id"/>-<xsl:value-of select="name()"/>
       
   826 	<xsl:value-of select="count(preceding-sibling::*)"/>
       
   827 </xsl:template>
       
   828 
       
   829 <xsl:template match="examples/cmp" mode="style-id">
       
   830 	<xsl:value-of select="concat('e',count(preceding::cmp[parent::examples]))"/>
       
   831 </xsl:template>
       
   832 
       
   833 
       
   834 </xsl:stylesheet>