sysmodellibs/sysmodelgen/src/old/svg/Model.xsl
changeset 6 5b32dc297d05
parent 1 b538b70cbe51
equal deleted inserted replaced
3:e7e0ae78773e 6:5b32dc297d05
       
     1 <?xml version="1.0"?>
       
     2  <!DOCTYPE XSLT  [
       
     3       <!ENTITY AZ  "ABCDEFGHIJKLMNOPQRSTUVWXYZ">
       
     4       <!ENTITY az  "abcdefghijklmnopqrstuvwxyz">
       
     5  ]>
       
     6  <xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"  xmlns:s="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:date="http://exslt.org/dates-and-times" exclude-result-prefixes="date exslt"
       
     7 		xmlns:exslt="http://exslt.org/common">
       
     8 	<xsl:param name="xml-stylesheet"/><!-- set to default stylesheet-->
       
     9 	<xsl:param name="Verbose" select="0"/><!-- Verbosity level of messages. Set to 1 (or higher) to get runtime comments-->
       
    10 	<xsl:param name="Origin-attr">old_model</xsl:param>
       
    11 	<xsl:output method="xml" cdata-section-elements="script s:script" indent="yes"/>
       
    12 	  <xsl:key name="named" match="*" use="@name"/>
       
    13 
       
    14 
       
    15 <!-- ====== Computed values ============= -->
       
    16 
       
    17 <xsl:variable name="Version">
       
    18 	<xsl:choose>
       
    19 		<xsl:when test="/model/@ver"><xsl:value-of select="/model/@ver"/></xsl:when>
       
    20 		<xsl:when test="/model/@deps"><xsl:value-of select="document(/model/@deps,.)/SystemModelDeps/@version"/></xsl:when>
       
    21 		<xsl:when test="count(/model/sysdef/info[@type='s12'])=1">
       
    22 			<xsl:value-of select="document(/model/sysdef/info[@type='s12']/@href,.)/Schedule12/@OS_version"/>
       
    23 		</xsl:when>
       
    24 	</xsl:choose>
       
    25 </xsl:variable>
       
    26 
       
    27 
       
    28 <!-- for merging: -->
       
    29 
       
    30 <xsl:variable name="filter-nodes" select="//filter[not(@accept or @reject) and @select and @display]"/>
       
    31 	<!--  @value is optional, but should be set unless select=* -->
       
    32 
       
    33 <xsl:variable name="filter-in"> <!--comma-separated list of filters to accept -->
       
    34 	<xsl:text>,</xsl:text>
       
    35 	<xsl:if test="not($filter-nodes) and //filter[@accept|@reject]">
       
    36 		<xsl:value-of  select="concat($Version,',')"/> <!-- the version number -->
       
    37 	</xsl:if>
       
    38 	<xsl:for-each select="//filter[@accept]"><xsl:value-of select="@accept"/>,</xsl:for-each>
       
    39 	<xsl:for-each select="//filter[@reject]">!<xsl:value-of select="@reject"/>,</xsl:for-each>
       
    40 </xsl:variable>
       
    41 
       
    42 
       
    43 <xsl:variable name="ignore" select="//ignore"/>
       
    44 
       
    45 <xsl:variable name="abbrevs" select="document(/model/layout/info/@href,/)/display-names//abbrev"/> <!-- the abbreviations list -->
       
    46 
       
    47 <xsl:variable name="simple-filters" select="not(function-available('exslt:node-set'))"/>
       
    48 
       
    49 <!-- ====== Error checking ============= -->
       
    50 
       
    51 <!--  start error checking -->
       
    52 
       
    53 <xsl:template match="SystemDefinition/@schema" mode="check">
       
    54 	<!-- warning if schema is less than 1.4 -->
       
    55 	<xsl:if test="substring-before(.,'.') &lt; 1 or (substring-before(.,'.')=1 and substring-before(substring-after(.,'.'),'.') &lt; 4)">
       
    56 		<xsl:call-template name="Caller-Warning"><xsl:with-param name="text">using old System Definition schema (<xsl:value-of select="."/>)</xsl:with-param></xsl:call-template>
       
    57 	</xsl:if>
       
    58 <!--	<xsl:if test="starts-with(.,'1.4.')">
       
    59 		<xsl:call-template name="Caller-Note"><xsl:with-param name="text">using backwards compatible System Definition schema (<xsl:value-of select="."/>)</xsl:with-param></xsl:call-template>
       
    60 	</xsl:if> -->
       
    61 	<xsl:if test="substring-before(.,'.') &gt; 2">
       
    62 		<xsl:call-template name="Critical-Error"><xsl:with-param name="text">using incompatible System Definition schema (<xsl:value-of select="."/>)</xsl:with-param></xsl:call-template>
       
    63 	</xsl:if>
       
    64 </xsl:template>
       
    65 
       
    66 <xsl:template match="*" mode="check"/>
       
    67 
       
    68 <xsl:template match="block[ancestor::layer/@levels]|lsubblock[ancestor::layer/@levels] | logicalset[ancestor::layer/@levels]|logicalsubset[ancestor::layer/@levels]" mode="check">
       
    69 	<xsl:variable name="levels"><xsl:text> </xsl:text><xsl:apply-templates mode="layernames" select="."/><xsl:text> </xsl:text></xsl:variable>	
       
    70 	<xsl:for-each select="module | collection">
       
    71 	<xsl:if test="not(contains($levels,concat(' ',@level,' ')))">
       
    72 		<xsl:call-template name="Caller-Error"><xsl:with-param name="text">Invalid level: <xsl:value-of select="@level"/> in <xsl:value-of select="@name"/></xsl:with-param></xsl:call-template>
       
    73 	</xsl:if>
       
    74 	</xsl:for-each>
       
    75 </xsl:template>
       
    76 
       
    77 <xsl:template name="Caller-Debug"><xsl:param name="text"/>
       
    78 	<xsl:if test="$Verbose &gt; 5"><xsl:message>&#xa;Note: <xsl:value-of select="$text"/></xsl:message></xsl:if>
       
    79 </xsl:template>
       
    80 <xsl:template name="Caller-Note"><xsl:param name="text"/>
       
    81 	<xsl:message>&#xa;Note: <xsl:value-of select="$text"/></xsl:message>
       
    82 </xsl:template>
       
    83 <xsl:template name="Caller-Warning"><xsl:param name="text"/>
       
    84 	<xsl:message>&#xa;Warning: <xsl:value-of select="$text"/></xsl:message>
       
    85 </xsl:template>
       
    86 <xsl:template name="Caller-Error"><xsl:param name="text"/>
       
    87 	<xsl:message>&#xa;Error: <xsl:value-of select="$text"/></xsl:message>
       
    88 </xsl:template>
       
    89 <xsl:template name="Critical-Error"><xsl:param name="text"/>
       
    90 	<xsl:message terminate="yes">&#xa;Error: <xsl:value-of select="$text"/></xsl:message>
       
    91 </xsl:template>
       
    92 
       
    93 <!--- ==================== merge ==================== -->
       
    94 
       
    95 <!-- merge is used this is called on a model file -->
       
    96 
       
    97 <xsl:template match="@*" mode="copyroot" priority="-1"><xsl:copy-of select="."/></xsl:template>
       
    98 <xsl:template match="@detail" mode="copyroot">
       
    99 	<xsl:choose>
       
   100 		<xsl:when test=".='module'"><xsl:attribute name="detail">collection</xsl:attribute></xsl:when>
       
   101 		<xsl:when test=".='logicalsubset'"><xsl:attribute name="detail">subblock</xsl:attribute></xsl:when>
       
   102 		<xsl:when test=".='logicalset'"><xsl:attribute name="detail">block</xsl:attribute></xsl:when>
       
   103 		<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
       
   104 	</xsl:choose>
       
   105 </xsl:template>
       
   106 
       
   107 
       
   108 <xsl:template match="@revision[../@revision-type='date' and contains(.,'%') and function-available('date:month-abbreviation')]" mode="copyroot">
       
   109 <xsl:attribute name="revision"><xsl:call-template name="format-date"/></xsl:attribute>
       
   110 </xsl:template>
       
   111 
       
   112 <xsl:template match="/model">
       
   113 	<xsl:if test="$xml-stylesheet!='' "> <!-- start with an optional style sheet transform -->
       
   114 		<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="<xsl:value-of select="$xml-stylesheet"/>"</xsl:processing-instruction>
       
   115 	</xsl:if>
       
   116 	<SystemDefinition>
       
   117 		<xsl:for-each select="document(sysdef/@href, .)/SystemDefinition">
       
   118 			<xsl:copy-of select="@* | namespace::*"/>
       
   119 		</xsl:for-each>
       
   120 	<xsl:copy-of select="document(layout/info[@type='abbrev']/@href,.)/*/@xml:lang"/> <!-- copy localized language value -->
       
   121 		<xsl:apply-templates select="document(@deps, .)/SystemModelDeps" mode="merge"/>
       
   122 		<styling>
       
   123 			<xsl:apply-templates select="@shapes | layout/info" mode="styling"/>
       
   124 		</styling>
       
   125 		<xsl:apply-templates select="document(sysdef/@href, .)/SystemDefinition/@schema" mode="check"/>
       
   126 		  <systemModel>
       
   127 			<!-- copy all attributes from all the system models and from the model element -->
       
   128 			<xsl:apply-templates select="document(sysdef/@href, .)/SystemDefinition/systemModel/@*|@*|layout/@*" mode="copyroot"/>
       
   129 			<xsl:if test="$Version!='' and not(@ver)">
       
   130 				<xsl:attribute name="ver">
       
   131 					<xsl:value-of select="$Version"/>
       
   132 				</xsl:attribute>
       
   133 			</xsl:if>
       
   134 			<!-- special handing of revision details -->
       
   135 			<xsl:choose><!-- get revision details from deps if not otherwise specified -->
       
   136 				<xsl:when test="@deps and (not(@revision-type) or @revision-type='build') and not(@revision)">
       
   137 					<xsl:variable name="rt" select="@revision-type"/>
       
   138 					<xsl:for-each select="document(@deps,.)/SystemModelDeps[@number]">
       
   139 						<xsl:if test="not($rt)">
       
   140 							<xsl:attribute name="revision-type">build</xsl:attribute>
       
   141 						</xsl:if>
       
   142 						<xsl:attribute name="revision"><xsl:value-of select="@number"/></xsl:attribute>
       
   143 					</xsl:for-each>
       
   144 				</xsl:when>
       
   145 				<xsl:when test="@revision-type='date' and not(@revision) and function-available('date:date-time')">
       
   146 					<xsl:attribute name="revision"><xsl:value-of select="substring-before(date:date-time(),'T')"/></xsl:attribute>
       
   147 				</xsl:when>
       
   148 			</xsl:choose>
       
   149 			<xsl:apply-templates select="layout/legend" mode="merge"/> <!-- add legend as a layer -->
       
   150 			<xsl:apply-templates select="layout/logo" mode="merge"/> <!-- copy logos to use when drawing: put first so it's drawn last-->
       
   151 			<xsl:choose>
       
   152 				<xsl:when test="not(function-available('exslt:node-set'))">
       
   153 					<!-- can't do much, don't bother filtering -->
       
   154 					<xsl:apply-templates select="sysdef" mode="merge"/>
       
   155 				</xsl:when>
       
   156 				<xsl:otherwise>
       
   157 					<xsl:for-each select="/model"> <!-- hack for xsltproc which loses the current node -->				
       
   158 					<xsl:variable name="unfiltered">
       
   159 							<xsl:choose>
       
   160 								<xsl:when test="count(sysdef) &lt; 2"> <!-- no need to merge multi models -->
       
   161 									<xsl:apply-templates select="sysdef" mode="merge"/>
       
   162 								</xsl:when>
       
   163 								<xsl:otherwise>
       
   164 									<xsl:variable name="sysdefs">
       
   165 										<xsl:for-each select="sysdef">
       
   166 											<sysdef><xsl:apply-templates select="." mode="merge"/></sysdef>
       
   167 										</xsl:for-each>
       
   168 									</xsl:variable>
       
   169 									<xsl:apply-templates select="exslt:node-set($sysdefs)/sysdef[1]" mode="override-merge">
       
   170 										<xsl:with-param name="next" select="exslt:node-set($sysdefs)/sysdef[2]"/>
       
   171 									</xsl:apply-templates>
       
   172 								</xsl:otherwise>
       
   173 							</xsl:choose>
       
   174 						</xsl:variable>
       
   175 						<xsl:apply-templates select="exslt:node-set($unfiltered)/*" mode="filter-for-presence"/>
       
   176 					</xsl:for-each>
       
   177 				</xsl:otherwise>
       
   178 			</xsl:choose>
       
   179 			<xsl:copy-of select="layout/layer-group"/> <!-- copy layer groups to use when drawing: put last so it's drawn first-->
       
   180 		  </systemModel>
       
   181 	</SystemDefinition>
       
   182 </xsl:template>
       
   183 
       
   184 
       
   185 <!-- merge multiple models together -->
       
   186 
       
   187 <xsl:template match="sysdef" mode="override-merge"><xsl:param name="next"/>
       
   188 	<xsl:choose>
       
   189 		<xsl:when test="not($next)">
       
   190 			<xsl:copy-of select="*"/>
       
   191 		</xsl:when>
       
   192 		<xsl:otherwise>
       
   193 			<xsl:call-template name="Caller-Note"><xsl:with-param name="text">Merging with model <xsl:value-of select="1 +  count($next/preceding-sibling::sysdef)"/></xsl:with-param></xsl:call-template>			
       
   194 			<xsl:variable name="cur">
       
   195 					<sysdef>
       
   196 						<xsl:apply-templates select="*" mode="override-merge">
       
   197 							<xsl:with-param name="other" select="$next"/>
       
   198 						</xsl:apply-templates>
       
   199 						<xsl:apply-templates select="$next/*" mode="append">
       
   200 							<xsl:with-param name="main" select="."/>
       
   201 						</xsl:apply-templates>
       
   202 					</sysdef>
       
   203 			</xsl:variable>
       
   204 			<xsl:apply-templates select="exslt:node-set($cur)/sysdef" mode="override-merge">
       
   205 				<xsl:with-param name="next" select="$next/following-sibling::sysdef[1]"/>
       
   206 			</xsl:apply-templates>	
       
   207 		</xsl:otherwise>
       
   208 	</xsl:choose>
       
   209 </xsl:template>
       
   210 
       
   211 <xsl:template match="component/*" mode="override-merge" priority="7"><xsl:copy-of select="."/></xsl:template>
       
   212 
       
   213 <xsl:template match="*" mode="override-merge"><xsl:param name="other"/>
       
   214 	<xsl:variable name="n" select="@name"/>
       
   215 	<xsl:variable name="tag" select="name()"/>
       
   216 	<xsl:choose>
       
   217 		<xsl:when test="$other/*[@override=$n and name()=$tag]"> 
       
   218 			<!--replace this with the other one at the current location-->
       
   219 			<xsl:apply-templates select="$other/*[@override=$n and name()=$tag]" mode="safe-combine">
       
   220 				<xsl:with-param name="main-root" select="ancestor-or-self::sysdef"/>
       
   221 			</xsl:apply-templates>
       
   222 		</xsl:when>
       
   223 		<xsl:when test="$other/ancestor-or-self::sysdef/descendant::*[@override=$n and name()=$tag]">
       
   224 			<!-- it's overridden somewhere else (perhaps deleted)-->
       
   225 			<xsl:call-template name="Caller-Note"><xsl:with-param name="text">Deleting  <xsl:value-of select="$n"/></xsl:with-param></xsl:call-template>			
       
   226 		</xsl:when>
       
   227 		<xsl:when test="$other/*[@rename=$n or @move=$n and name()=$tag]"> <!-- leave as is at the current location-->
       
   228 			<xsl:if test="$other/*[@rename=$n or @move=$n and name()=$tag]/*">
       
   229 			<xsl:call-template name="Caller-Warning"><xsl:with-param name="text">ignoring children</xsl:with-param></xsl:call-template>
       
   230 			</xsl:if>
       
   231 			<xsl:copy>
       
   232 				<xsl:copy-of select="@*"/> <!-- own attributes -->
       
   233 				<xsl:copy-of select="$other/*[@rename=$n or @move=$n and name()=$tag]/@name"/> <!-- overwrite names -->
       
   234 			<!--leave as is at the current location-->					
       
   235 				<xsl:apply-templates select="*[not(self::name)]"  mode="override-merge"> <!-- do not copy deprecated localised name form-->
       
   236 					<xsl:with-param name="other" select="$other/ancestor-or-self::sysdef"/> <!-- use root of other, to catch any moved decendants -->
       
   237 				</xsl:apply-templates>
       
   238 			</xsl:copy>
       
   239 		</xsl:when>
       
   240 		<xsl:when test="$other/ancestor-or-self::sysdef/descendant::*[@rename=$n or @move=$n and $tag=name()]">
       
   241 			<!--it's moved to elsewhere-->
       
   242 			<xsl:call-template name="Caller-Note"><xsl:with-param name="text">Relocating <xsl:value-of select="$n"/></xsl:with-param></xsl:call-template>
       
   243 		</xsl:when>
       
   244 		<xsl:when test="$other/*[@name=$n and self::component]">
       
   245 			<!--use other at the current location-->
       
   246 			<xsl:copy>
       
   247 				<xsl:copy-of select="$other/*[@name=$n and name()=$tag]/@*"/> <!--other's attributes -->
       
   248 				<!-- should put something here to merge filters,classes properly -->
       
   249 				<xsl:copy-of select="*"/> <!--current conent -->
       
   250 					<xsl:variable name="this" select="."/>
       
   251 				<xsl:apply-templates mode="copy-merge-content"  select="$other/*[@name=$n and name()=$tag]/*">
       
   252 					<xsl:with-param name="main" select="$this"/>
       
   253 				</xsl:apply-templates> <!--other's conent -->
       
   254 			</xsl:copy>
       
   255 		</xsl:when>
       
   256 		<xsl:when test="$other/*[@name=$n and name()=$tag]"> <!-- leave as is at the current location, merge children-->
       
   257 			<xsl:for-each select="$other/*[@name=$n and name()=$tag]">
       
   258 				<xsl:if test="(self::module and $tag!='module') or (not(self::module) and $tag='module')   or   (self::collection and $tag!='collection') or (not(self::collection) and $tag='collection')">
       
   259 					<xsl:call-template name="Critical-Error"><xsl:with-param name="text">Cannot merge <xsl:value-of select="name()"/> "<xsl:value-of select="@name"/>" with <xsl:value-of select="$tag"/> "<xsl:value-of select="$n"/>"</xsl:with-param></xsl:call-template>				
       
   260 				</xsl:if>
       
   261 			</xsl:for-each>
       
   262 			<xsl:copy>
       
   263 				<xsl:copy-of select="@*"/> <!-- own attributes -->
       
   264 				<xsl:copy-of select="$other/*[@name=$n and name()=$tag]/@*"/> <!-- other's attributes -->
       
   265 				<xsl:apply-templates select="*"  mode="override-merge">
       
   266 					<xsl:with-param name="other" select="$other/*[@name=$n and name()=$tag]"/> <!-- use other version of this -->
       
   267 				</xsl:apply-templates>
       
   268 			</xsl:copy>
       
   269 		</xsl:when>
       
   270 		<xsl:when test="$other/ancestor-or-self::sysdef/descendant::*[@name=$n and name()=$tag]">
       
   271 			<!-- it's moved to elsewhere -->
       
   272 			<xsl:call-template name="Caller-Note"><xsl:with-param name="text">Relocating and merging <xsl:value-of select="$n"/></xsl:with-param></xsl:call-template>
       
   273 		</xsl:when>
       
   274 		<xsl:otherwise> <!--  there is no equivalent in 2nd, just copy this and descend -->
       
   275 			<xsl:copy>
       
   276 				<xsl:copy-of select="@*"/> <!-- own attributes -->	
       
   277 				<xsl:apply-templates select="*"  mode="override-merge">
       
   278 					<xsl:with-param name="other" select="$other/ancestor-or-self::sysdef"/> <!-- use root of other, to catch any moved decendants -->
       
   279 				</xsl:apply-templates>
       
   280 			</xsl:copy>		
       
   281 		</xsl:otherwise>
       
   282 	</xsl:choose>
       
   283 	<!-- this won't work if the main model has nothing in the group, but that's invalid, so it's ok. -->
       
   284 	<xsl:if test="position()=last() and name($other)!='sysdef'">
       
   285 		<!--Check if other has stuff to append that's not already been used   -->
       
   286 		<xsl:apply-templates select="$other/*" mode="append">
       
   287 			<xsl:with-param name="main" select=".."/>
       
   288 		</xsl:apply-templates>		
       
   289 	</xsl:if>
       
   290 </xsl:template>
       
   291 
       
   292 
       
   293 <xsl:template mode="copy-merge-content" match="*">
       
   294 <xsl:copy-of select="."/>
       
   295 </xsl:template>
       
   296 
       
   297 
       
   298 <xsl:template mode="copy-merge-content" match="component/*[starts-with(name(),'generator-')]"><xsl:param name="main"/>
       
   299 	<xsl:variable name="self" select="."/>
       
   300 	<!-- only copy if does not exist in original -->
       
   301 	<xsl:if test="not($main/*[name()=name($self)])">
       
   302 		<xsl:copy-of select="$self"/>
       
   303 	</xsl:if>
       
   304 </xsl:template>
       
   305 
       
   306 <xsl:template mode="copy-merge-content" match="unit"><xsl:param name="main"/>
       
   307 	<xsl:variable name="attr"><xsl:for-each select="@*"><xsl:value-of select="concat(name(),'=',.)"></xsl:value-of></xsl:for-each></xsl:variable>
       
   308 	<xsl:variable name="exists">
       
   309 		<xsl:for-each select="$main/unit">
       
   310 			<xsl:variable name="attr2"><xsl:for-each select="@*"><xsl:value-of select="concat(name(),'=',.)"></xsl:value-of></xsl:for-each></xsl:variable>
       
   311 			<xsl:if test="$attr2=$attr">*</xsl:if>
       
   312 		</xsl:for-each>
       
   313 	</xsl:variable>
       
   314 	<!-- only copy if does not exist in original's units-->
       
   315 	<xsl:if test="$exists=''">
       
   316 		<xsl:copy-of select="."/>
       
   317 	</xsl:if>
       
   318 </xsl:template>
       
   319 
       
   320 
       
   321 
       
   322 <xsl:template match="*[@override  and *]" mode="append" priority="5"><xsl:param name="main"/>
       
   323 	<xsl:call-template name="Caller-Debug"><xsl:with-param name="text">Append (5) <xsl:value-of select="@name"/></xsl:with-param></xsl:call-template>	
       
   324 
       
   325 	<xsl:variable name="n" select="@override"/>
       
   326 		<!-- if override is not in main, use this -->
       
   327 	<xsl:if test="@name and not($main/*[@name=$n])">
       
   328 		<!--  must have a name for renaming -->
       
   329 		<xsl:copy>
       
   330 			<xsl:copy-of select="@*[not(name()='override' or name()='rename' or name()='move')]"/>
       
   331 			<xsl:apply-templates select="*" mode="safe-combine">
       
   332 				<xsl:with-param name="main-root" select="$main/ancestor-or-self::sysdef"/>
       
   333 			</xsl:apply-templates>	
       
   334 		</xsl:copy>
       
   335 	</xsl:if>
       
   336 </xsl:template>
       
   337 
       
   338 <xsl:template match="*" mode="safe-combine" priority="-1"><xsl:param name="main-root"/>
       
   339 	<xsl:copy>
       
   340 		<xsl:copy-of select="@*"/>
       
   341 		<xsl:apply-templates select="*"  mode="safe-combine">
       
   342 			<xsl:with-param name="main-root" select="$main-root"/>
       
   343 		</xsl:apply-templates>
       
   344 	</xsl:copy>
       
   345 </xsl:template>
       
   346 
       
   347 <xsl:template match="*[@rename or @move]" mode="safe-combine" priority="3"><xsl:param name="main-root"/>
       
   348 	<xsl:variable name="n" select="@rename | @move"/>
       
   349 	<xsl:variable name="newname" select="@name"/>
       
   350 	<xsl:variable name="atts" select="@*[name()!='name' and name()!='move' and name()!='rename' and name()!='override']"/> <!-- if any non-oragnisational attributes are present on the "move" item, then they should override the values in the thing being moved -->
       
   351 	<xsl:variable name="other" select="ancestor-or-self::sysdef"/>
       
   352 	<!-- can't merge a component with a container -->
       
   353 	<xsl:for-each select="$main-root/descendant::*[@name=$n and (self::layer or self::block or self::subblock or self::logicalset or self::logicalsubset)]">
       
   354 		<xsl:copy>
       
   355 			<xsl:copy-of select="@*"/>
       
   356 			<xsl:copy-of select="$newname"/>	
       
   357 			<xsl:copy-of select="$atts"/> <!-- if any of these attributes are present on the moved collection, then use that value rather than the value in the one being moved -->
       
   358 			<xsl:apply-templates select="*"  mode="override-merge"> <!-- do not copy localised name -->
       
   359 				<xsl:with-param name="other" select="$other"/>
       
   360 			</xsl:apply-templates>
       
   361 		</xsl:copy>
       
   362 	</xsl:for-each>	
       
   363 </xsl:template>
       
   364 <!-- can only merge a component or module with component or module -->
       
   365 <xsl:template match="component[@rename or @move] | collection[@rename or @move] | module[@rename or @move]" mode="safe-combine" priority="4"><xsl:param name="main-root"/>
       
   366 	<xsl:variable name="n" select="@rename | @move"/>
       
   367 	<xsl:variable name="newname" select="@name"/>
       
   368 	<xsl:variable name="atts" select="@*[name()!='name' and name()!='move' and name()!='rename' and name()!='override']"/> <!-- if any non-oragnisational attributes are present on the "move" item, then they should override the values in the thing being moved -->
       
   369 	<xsl:variable name="tag" select="name()"/>
       
   370 	<xsl:variable name="other" select="ancestor-or-self::sysdef"/>	
       
   371 	<!-- can't merge a component with a container -->
       
   372 	<xsl:for-each select="$main-root/descendant::*[@name=$n and $tag=name()]">
       
   373 		<xsl:copy>
       
   374 			<xsl:copy-of select="@*"/>
       
   375 			<xsl:copy-of select="$newname"/>	
       
   376 			<xsl:copy-of select="$atts"/> <!-- if any of these attributes are present on the moved collection, then use that value rather than the value in the one being moved -->
       
   377 			<xsl:apply-templates select="*[not(self::name)]"  mode="override-merge"> <!-- do not copy localised name -->
       
   378 				<xsl:with-param name="other" select="$other"/>
       
   379 			</xsl:apply-templates>
       
   380 		</xsl:copy>
       
   381 	</xsl:for-each>	
       
   382 </xsl:template>
       
   383 
       
   384 
       
   385 <xsl:template match="*[@name]" mode="safe-combine" priority="2"><xsl:param name="main-root"/>
       
   386 	<xsl:if test="@override and (@rename or @move)">
       
   387 		<xsl:call-template name="Critical-Error"><xsl:with-param name="text">Error invalid combinations of attributes in <xsl:value-of select="@name"/></xsl:with-param></xsl:call-template>
       
   388 	</xsl:if>
       
   389 	<xsl:copy>
       
   390 		<xsl:variable name="cur" select="."/>
       
   391 		<xsl:copy-of select="@*[not(name()='override' or name()='rename' or name()='move')]"/>
       
   392 		<!-- copy other's attributes -->
       
   393 		<xsl:copy-of select="$main-root/descendant::*[@name=$cur/@name and name($cur)=name()]/@*[not(name()='override' or name()='rename' or name()='move' or name()='name')]"/>		
       
   394 		<xsl:apply-templates select="*"  mode="safe-combine">
       
   395 			<xsl:with-param name="main-root" select="$main-root"/>
       
   396 		</xsl:apply-templates>
       
   397 		<!-- now copy anything defined here -->
       
   398 		<xsl:variable name="other" select="ancestor-or-self::sysdef"/>	
       
   399 		<xsl:for-each select="$main-root/descendant::*[@name=$cur/@name and name($cur)=name()]">
       
   400 			<xsl:apply-templates select="*[not(self::name)]"  mode="override-merge"> <!-- do not copy localised name -->
       
   401 				<xsl:with-param name="other" select="$other"/>
       
   402 			</xsl:apply-templates>
       
   403 		</xsl:for-each>	
       
   404 	</xsl:copy>
       
   405 </xsl:template>
       
   406 
       
   407 <xsl:template match="component | component/*" mode="safe-combine" priority="2">
       
   408 	<!--a component is atomic: it cannot be merged. So it's always just copied.-->	
       
   409 	<xsl:copy-of select="."/>
       
   410 </xsl:template>
       
   411 
       
   412 
       
   413 <xsl:template match="*[@override and not(@name)]" mode="safe-combine" priority="5"/> <!-- ignore component -->
       
   414 
       
   415 
       
   416 <xsl:template match="*" mode="unused-merge"><xsl:param name="other"/>
       
   417 	<xsl:variable name="self" select="."/>
       
   418 	<xsl:if test="not($other/descendant::*[@name=$self/@name and name()=name($self)  and descendant-or-self::component])">
       
   419 		<!-- not in other, so include here -->
       
   420 		<xsl:copy>
       
   421 			<xsl:copy-of select="@*"/>
       
   422 			<xsl:apply-templates select="*"  mode="unused-merge">
       
   423 				<xsl:with-param name="other" select="$other"/>
       
   424 			</xsl:apply-templates>
       
   425 		</xsl:copy>
       
   426 	</xsl:if>
       
   427 </xsl:template>
       
   428 
       
   429 <xsl:template match="*[@name]" mode="append"><xsl:param name="main"/>
       
   430 	<!--  this handles all cases where this holds the data -->
       
   431 	<xsl:variable name="self" select="."/>
       
   432 		<!-- if $self is not in main, use this -->
       
   433 	<xsl:if test="not($main/*[@name=$self/@name])">
       
   434 		<xsl:variable name="other" select="ancestor-or-self::sysdef"/>
       
   435 		<xsl:for-each select="$main/ancestor-or-self::sysdef/descendant::*[@name=$self/@name and name()=name($self)  and descendant-or-self::component]">
       
   436 			<xsl:call-template name="Caller-Debug"><xsl:with-param name="text">To Merge <xsl:value-of select="$self/@name"/> with these: <xsl:for-each select="*">"<xsl:value-of select="@name"/>", </xsl:for-each></xsl:with-param></xsl:call-template>	
       
   437 			<xsl:copy>
       
   438 				<xsl:copy-of select="@*"/>
       
   439 				<xsl:apply-templates select="*"  mode="override-merge">
       
   440 					<xsl:with-param name="other" select="$other"/>
       
   441 				</xsl:apply-templates>
       
   442 	<xsl:comment>was not here</xsl:comment>
       
   443 				<xsl:apply-templates select="$other/descendant::*[@name=$self/@name and name()=name($self) and descendant-or-self::component]/*"  mode="unused-merge">
       
   444 					<xsl:with-param name="other" select="$main"/>
       
   445 				</xsl:apply-templates>
       
   446 	<xsl:comment>end not here</xsl:comment>
       
   447 			</xsl:copy>
       
   448 		</xsl:for-each>
       
   449 		<!-- if it does not already exist, create it and check all children -->
       
   450 		<xsl:if test="not($main/ancestor-or-self::sysdef/descendant::*[@name=$self/@name and name()=name($self) and descendant-or-self::component])">
       
   451 			<xsl:call-template name="Caller-Debug"><xsl:with-param name="text">Does not already exist: <xsl:value-of select="$self/@name"/> </xsl:with-param></xsl:call-template>	
       
   452 			<xsl:copy>
       
   453 				<xsl:copy-of select="@*"/>
       
   454 				<xsl:apply-templates select="*"  mode="safe-combine">
       
   455 					<xsl:with-param name="main-root" select="$main/ancestor-or-self::sysdef"/>
       
   456 				</xsl:apply-templates>
       
   457 			</xsl:copy>			
       
   458 		</xsl:if>
       
   459 	</xsl:if>
       
   460 </xsl:template>
       
   461 
       
   462 <xsl:template match="component[@name]" mode="append" priority="1"><xsl:param name="main"/>
       
   463 	<xsl:variable name="n" select="@name"/>
       
   464 		<!-- if $n is not in main, use this -->
       
   465 	<xsl:if test="not($main/*[@name=$n])">	
       
   466 		<xsl:copy-of select="."/>
       
   467 	</xsl:if>
       
   468 </xsl:template>
       
   469 
       
   470 
       
   471 <xsl:template match="*[@rename or @move]" mode="append" priority="4"><xsl:param name="main"/>
       
   472 	<xsl:call-template name="Caller-Debug"><xsl:with-param name="text">Append (4) <xsl:value-of select="@name"/></xsl:with-param></xsl:call-template>	
       
   473 	<xsl:variable name="n" select="@rename | @move"/>
       
   474 		<!-- if $n is not in main, use this -->
       
   475 	<xsl:if test="not($main/*[@name=$n])">	
       
   476 		<xsl:apply-templates select="." mode="safe-combine">
       
   477 			<xsl:with-param name="main-root" select="$main/ancestor-or-self::sysdef"/>
       
   478 		</xsl:apply-templates>	
       
   479 	</xsl:if>
       
   480 </xsl:template>
       
   481 
       
   482 <!-- merging data sources  -->
       
   483 <xsl:template match="sysdef" mode="merge">
       
   484 	<xsl:apply-templates select="document(@href)/SystemDefinition/systemModel/*" mode="merge">
       
   485 		<xsl:with-param name="extra-files" select="info|../@deps|../@ts|../layout/info[@type and document(@href,.)/values]|../layout/display|@root"/>
       
   486 	</xsl:apply-templates>
       
   487 </xsl:template>
       
   488 
       
   489 
       
   490 <xsl:template match="SystemModelDeps" mode="merge">
       
   491 	<xsl:if test="@name or @version or @number">
       
   492 		<release><xsl:copy-of select="@name | @version | @number"/></release>
       
   493 	</xsl:if>
       
   494 </xsl:template>
       
   495 
       
   496 <!-- merge model with extra -->
       
   497 
       
   498 <xsl:template match="layer" mode="merge"><xsl:param name="extra-files"/>
       
   499 	<xsl:variable name="e"><xsl:call-template name="is-present"/></xsl:variable>	
       
   500 	<xsl:if test="$e!=''">
       
   501 		<xsl:copy><xsl:copy-of select="@*"/> 
       
   502 			<xsl:variable name="name" select="@name"/>
       
   503 			<xsl:copy-of select="$extra-files[self::display and @name=$name]/@*[name()!='name']"/>
       
   504 			<xsl:if test="$extra-files[@type='levels']"><!-- levels hack for older models -->
       
   505 				<xsl:copy-of select="document($extra-files[@type='levels']/@href,$extra-files)//layer[@name=$name]/@*[name()='levels' or name()='span']"/>
       
   506 			</xsl:if>
       
   507 			<xsl:apply-templates select="$extra-files[@type='extra']" mode="merge-attributes">
       
   508 				<xsl:with-param name="cmp" select="."/>			
       
   509 			</xsl:apply-templates>
       
   510 			<xsl:if test="@name='Programming Support' and not(@span)"><xsl:attribute name="span">2</xsl:attribute></xsl:if> <!-- hack!!!!! -->
       
   511 			<xsl:call-template name="abbrev"/>
       
   512 		 	<xsl:apply-templates select="*" mode="merge">
       
   513 				<xsl:with-param name="extra-files" select="$extra-files"/>
       
   514 			</xsl:apply-templates>
       
   515 		</xsl:copy>
       
   516 	</xsl:if>
       
   517 </xsl:template>
       
   518 
       
   519 
       
   520 <!-- hack for old models -->
       
   521 <xsl:template match="logicalsubset[@name='J2ME']" mode="merge" priority="5"><xsl:param name="extra-files"/>
       
   522 	<xsl:apply-templates select="*" mode="merge">
       
   523 		<xsl:with-param name="extra-files" select="$extra-files"/>
       
   524 	</xsl:apply-templates>
       
   525 </xsl:template>
       
   526 
       
   527 <!-- update old model names, these could be done as a set of templates instead.
       
   528 	I've no idea which is more efficient -->
       
   529 <xsl:template match="*" mode="item-tag">
       
   530 	<xsl:choose>
       
   531 		<xsl:when test="self::module">collection</xsl:when>
       
   532 		<xsl:when test="self::logicalset">block</xsl:when>
       
   533 		<xsl:when test="self::logicalsubset">subblock</xsl:when>
       
   534 		<xsl:otherwise><xsl:value-of select="name()"/></xsl:otherwise>
       
   535 	</xsl:choose>
       
   536 </xsl:template>
       
   537 
       
   538 <xsl:template match="*" mode="alt-tag"> <!-- for compatability-->
       
   539 	<xsl:choose>
       
   540 		<xsl:when test="self::collection">module</xsl:when>
       
   541 		<xsl:when test="self::block">logicalset</xsl:when>
       
   542 		<xsl:when test="self::subblock">logicalsubset</xsl:when>
       
   543 		<xsl:otherwise><xsl:value-of select="name()"/></xsl:otherwise>
       
   544 	</xsl:choose>
       
   545 </xsl:template>
       
   546 
       
   547 <xsl:template match="collection|block|subblock | module|logicalset|logicalsubset" mode="merge"><xsl:param name="extra-files"/>
       
   548 	<xsl:variable name="e"><xsl:call-template name="is-present"/></xsl:variable>
       
   549 	<xsl:if test="$e!=''">	
       
   550 		<xsl:variable name="tag"><xsl:apply-templates mode="item-tag" select="."/></xsl:variable>
       
   551 		<xsl:variable name="alt-tag"><xsl:apply-templates mode="alt-tag" select="."/></xsl:variable>
       
   552 		<xsl:element name="{$tag}">
       
   553 			<xsl:copy-of select="@*"/>
       
   554 			<xsl:variable name="name" select="@name"/>
       
   555 			<xsl:copy-of select="$extra-files[self::display and @name=$name]/@*[name()!='name']"/>		
       
   556 			<xsl:if test="not(self::logicalsubset or self::subblock) and $extra-files[@type='levels']">
       
   557 				<xsl:copy-of select="document($extra-files[@type='levels']/@href,$extra-files)//*[@name=$name and (name()=$tag or name()=$alt-tag)]/@*[starts-with(name(),'level') or name()='span']"/>
       
   558 			</xsl:if>
       
   559 			<xsl:apply-templates select="$extra-files[@type='extra']" mode="merge-attributes">
       
   560 				<xsl:with-param name="cmp" select="."/>			
       
   561 			</xsl:apply-templates>			
       
   562 			<xsl:call-template name="abbrev"/>	
       
   563 			<xsl:apply-templates select="*" mode="merge">
       
   564 				<xsl:with-param name="extra-files" select="$extra-files"/>
       
   565 			</xsl:apply-templates>	  
       
   566 		</xsl:element>
       
   567 	</xsl:if>
       
   568 </xsl:template>
       
   569 
       
   570 <!-- sched 12 -->
       
   571 
       
   572 <xsl:template match="Schedule12/*[@name]" mode="merge">
       
   573 	<s12>
       
   574 		<!-- allow multiple s12 in a component so shapes can pick the right one for the supplied version-->
       
   575 		<xsl:attribute name="ver"><xsl:value-of select="/Schedule12/@OS_version"/></xsl:attribute>
       
   576 		<xsl:apply-templates select="." mode="osd"/>
       
   577 		<xsl:copy-of select="@name"/>
       
   578 	</s12>
       
   579 </xsl:template>
       
   580 
       
   581 <xsl:template match="*" mode="osd"> <!-- CR, OS, OR, CS or anything new -->
       
   582 	<xsl:attribute name="osd"><xsl:value-of select="name()"/></xsl:attribute>
       
   583 </xsl:template>
       
   584 
       
   585 <xsl:template match="REF" mode="osd">
       
   586 	<xsl:attribute name="osd">T-R</xsl:attribute>
       
   587 	<xsl:attribute name="ref">true</xsl:attribute>
       
   588 </xsl:template>
       
   589 
       
   590 <xsl:template match="TEST|RT" mode="osd">
       
   591 	<xsl:attribute name="osd">T-R</xsl:attribute>
       
   592 </xsl:template>
       
   593 
       
   594 <!--/sched 12 -->
       
   595 
       
   596 <!-- filters -->
       
   597 
       
   598 
       
   599 
       
   600 <xsl:template name="is-present">
       
   601 	<!-- use this for filtering if we need to use simple filtering
       
   602 		only necessary if we can't use node-set filters -->
       
   603 	<xsl:choose>
       
   604 		<xsl:when test="not($simple-filters)">1</xsl:when>
       
   605 		<xsl:otherwise>
       
   606 			<xsl:variable name="show">
       
   607 				<xsl:apply-templates select="." mode="filter-value"/>
       
   608 			</xsl:variable>
       
   609 			<!-- filter accept="..." takes precedence over "rich" filters, so if the rich filter
       
   610 				says the item is present, then we still need to check to see if it should be
       
   611 				shown via the mode="present" template	-->
       
   612 			<xsl:if test="$show='' or $show='show'">
       
   613 				<xsl:apply-templates select="." mode="present"/>
       
   614 			</xsl:if>
       
   615 		</xsl:otherwise>
       
   616 	</xsl:choose>
       
   617 </xsl:template>
       
   618 
       
   619 <xsl:template match="component" mode="present" priority="8">
       
   620 	<xsl:variable name="e"><xsl:apply-templates select="unit|package|prebuilt" mode="present"/></xsl:variable>
       
   621 	<xsl:if test="$e!='' or not(unit|package|prebuilt)">1</xsl:if>
       
   622 </xsl:template>
       
   623 
       
   624 <xsl:template match="layer|block|subblock|collection | module|logicalset|logicalsubset" mode="present" priority="9">
       
   625 	<xsl:variable name="t" select="name()"/><xsl:variable name="n" select="@name"/>
       
   626 	<xsl:variable name="alt"><xsl:apply-templates select="." mode="alt-tag"/></xsl:variable>
       
   627 	<xsl:if test="not($ignore[(@type=$t or @type=$alt) and @name=$n])"> <!-- matches either e.g. module or colelction -->
       
   628 		<xsl:apply-templates select="descendant::component" mode="present"/>
       
   629 	</xsl:if>
       
   630 </xsl:template>
       
   631 
       
   632 <xsl:template match="component[@filter]" mode="present" priority="9">
       
   633 	<!-- if there's a filter then check to see if this is filtered out -->
       
   634 	<xsl:variable name="e0"><xsl:call-template name="present"/></xsl:variable>
       
   635 	<xsl:if test="$e0!=''">
       
   636 		<xsl:variable name="e1"><xsl:apply-templates select="unit|package|prebuilt" mode="present"/></xsl:variable>
       
   637 		<xsl:if test="$e1!=''  or not(unit|package|prebuilt)">1</xsl:if>
       
   638 	</xsl:if>
       
   639 </xsl:template>
       
   640 
       
   641 <xsl:template match="*[not(@filter)]" mode="present" priority="5">1</xsl:template> <!-- if no filter, must always be valid -->
       
   642 <xsl:template match="*[@filter]" mode="present"><xsl:call-template name="present"/></xsl:template>
       
   643 
       
   644 <xsl:template match="*[contains(@filter,',')]" mode="present">	
       
   645 	<!-- if the number of comma-separated items is the same as the number of items present, then this is present (ie we're ANDing the items)-->
       
   646 	<xsl:variable name="present"><xsl:call-template name="present-list"/></xsl:variable>
       
   647 	<xsl:if test="string-length(@filter) - string-length(translate(@filter,',','')) + 1 = string-length($present)">1</xsl:if>
       
   648 </xsl:template>	
       
   649 
       
   650 <xsl:template name="present-list"><xsl:param name="filter" select="@filter"/>
       
   651 	<xsl:call-template name="present">
       
   652 		<xsl:with-param name="filter">	<xsl:choose>
       
   653 			<xsl:when test="contains($filter,',')"><xsl:value-of select="substring-before($filter,',')"/></xsl:when>
       
   654 			<xsl:otherwise><xsl:value-of select="$filter"/></xsl:otherwise>
       
   655 		</xsl:choose></xsl:with-param>
       
   656 	</xsl:call-template>
       
   657 	<xsl:if test="contains($filter,',')"><xsl:call-template name="present-list">
       
   658 		<xsl:with-param name="filter" select="substring-after($filter,',')"/>
       
   659 	</xsl:call-template></xsl:if>
       
   660 </xsl:template>
       
   661 
       
   662 <xsl:template name="present"><xsl:param name="filter" select="@filter"/>
       
   663 	<xsl:choose>
       
   664 		<xsl:when test="$filter-in=',' and $filter-nodes">1</xsl:when> <!-- accept everything -->
       
   665 		<xsl:when test="contains($filter-in,concat(',',$filter,','))">1</xsl:when> <!-- accept anything explictly on accept list -->
       
   666 		<xsl:when test="starts-with($filter,'!') and contains($filter-in,concat(',',substring($filter,2),','))"/> <!--reject if expliftly to accept a something with a "not" -->
       
   667 		<xsl:when test="starts-with($filter,'!')">1</xsl:when> <!--it's not on the must-have list, so accept it -->
       
   668 		<!-- reject otherwise -->
       
   669 	</xsl:choose>
       
   670 </xsl:template>
       
   671 <!-- node-set filters -->
       
   672 
       
   673 <xsl:template mode="filter-for-presence" match="comment() | node()" priority="-1"><xsl:copy-of select="."/></xsl:template>
       
   674 
       
   675 <xsl:template mode="filter-for-presence" match="layer|block|subblock|collection | logicalset|logicalsubset|module">
       
   676 	<xsl:variable name="t" select="name()"/>
       
   677 	<xsl:variable name="alt"><xsl:apply-templates select="." mode="alt-tag"/></xsl:variable>	<!-- for bkward compat -->
       
   678 	<xsl:variable name="n" select="@name"/>
       
   679 	<xsl:if test="not($ignore[(@type=$t or @type=$alt) and @name=$n])">
       
   680 		<xsl:variable name="content">
       
   681 			<xsl:apply-templates  select="comment() | *" mode="filter-for-presence"/>
       
   682 		</xsl:variable>
       
   683 		<xsl:if test="exslt:node-set($content)/*">
       
   684 			<xsl:copy><xsl:copy-of select="@*"/>
       
   685 				<xsl:copy-of select="$content"/>
       
   686 			</xsl:copy>
       
   687 		</xsl:if>
       
   688 	</xsl:if>
       
   689 </xsl:template>
       
   690 
       
   691 <xsl:template match="filter" mode="filter-values"><xsl:param name="c"/>
       
   692 	<xsl:variable name="att" select="@select"/>
       
   693 	<xsl:choose>
       
   694 		<xsl:when test="not($c[self::component])"/>
       
   695 		<xsl:when test="@select='*'"> <!-- always matches -->
       
   696 				<xsl:value-of select="concat(' ',@display)"/>
       
   697 		</xsl:when>
       
   698 		<xsl:when test="not($c/@*[name()=$att] or $c/*[self::unit or self::package or self::prebuilt]/@*[name()=$att])"/> <!-- this filter does not match this component-->
       
   699 		<xsl:when test="not(@value) or @value='*'">	<!-- true if just checking for the presence of the attribute on the item -->
       
   700 				<xsl:value-of select="concat(' ',@display)"/>
       
   701 		</xsl:when>
       
   702 		<xsl:when test="@select='filter'">
       
   703 			<!--  @value must be in the comma-separated list of filter on this or child-->
       
   704 			<xsl:if test="contains(concat(',',$c/@filter,',',$c/*/@filter,','),concat(',',@value,','))">
       
   705 				<xsl:value-of select="concat(' ',@display)"/>
       
   706 			</xsl:if>
       
   707 		</xsl:when>
       
   708 		<xsl:when test="@select='class'">
       
   709 			<!--  @value must be in the whitespace-separated list -->
       
   710 			<xsl:if test="contains(concat(' ',normalize-space($c/@class),' '),concat(' ',@value,' '))">
       
   711 				<xsl:value-of select="concat(' ',@display)"/>
       
   712 			</xsl:if>
       
   713 		</xsl:when>
       
   714 		<!--  any other attribute must match exactly on the component -->
       
   715 		<xsl:when test="@value= $c/@*[name()=$att]">
       
   716 				<xsl:value-of select="concat(' ',@display)"/>
       
   717 		</xsl:when>
       
   718 		<!--  other attributes on unit children must also match exactly -->
       
   719 		<xsl:when test="@value= $c/*/@*[name()=$att]">
       
   720 				<xsl:value-of select="concat(' ',@display)"/>
       
   721 		</xsl:when>
       
   722 	</xsl:choose>	
       
   723 </xsl:template>
       
   724 
       
   725 
       
   726 <xsl:template match="*" mode="filter-value"/> <!-- no filter value unless otherwise specified -->
       
   727 <xsl:template match="component" priority="1"  mode="filter-value"> <!-- only components can have "rich" filters, though some attributes can apply to units-->
       
   728 	<xsl:variable name="this" select="."/>
       
   729 	<xsl:call-template name="last-in-list">
       
   730 		<xsl:with-param name="str">
       
   731 			<xsl:apply-templates select="$filter-nodes" mode="filter-values">
       
   732 				<xsl:with-param name="c" select="$this"/>
       
   733 			</xsl:apply-templates>
       
   734 		</xsl:with-param>
       
   735 	</xsl:call-template>
       
   736 </xsl:template>
       
   737 
       
   738 <!-- this will add a display="..." attribute to the item for any display value other than
       
   739 	'hide' (which does not include the item in the output) and
       
   740 	'show' (which includes the item, but the attribtue is not needed, since it should appear like any other item) -->
       
   741 <xsl:template mode="filter-for-presence" match="component|unit|package|prebuilt" priority="1">
       
   742 	<xsl:variable name="show">
       
   743 		<xsl:apply-templates select="." mode="filter-value"/>
       
   744 	</xsl:variable>
       
   745 	<xsl:if test="$show='' or $show!='hide'">	
       
   746 		<xsl:variable name="this" select="."/>
       
   747 		<xsl:if test="not($ignore[@type=name($this) and $this/@name=@name])"> 	<!-- hide component if specifically told to ignore -->
       
   748 			<xsl:variable name="e"><xsl:apply-templates select="." mode="present"/></xsl:variable>
       
   749 			<!-- show component if any CBRs survive the filters or this is a placeholder with no content -->
       
   750 			<xsl:choose>
       
   751 				<xsl:when test="$e='' "/> <!-- filtered out, don't show -->
       
   752 				<xsl:when test="self::component">
       
   753 					<xsl:variable name="content">
       
   754 						<xsl:apply-templates  select="comment() | *" mode="filter-for-presence"/>
       
   755 					</xsl:variable>
       
   756 					<xsl:if test="exslt:node-set($content)/* or not(*)"> <!-- show all empty components -->
       
   757 						<xsl:copy><xsl:copy-of select="@*"/>
       
   758 							<xsl:if test="$show!='' and $show!='show'"><xsl:attribute name="display"><xsl:value-of select="$show"/></xsl:attribute></xsl:if>
       
   759 							<xsl:copy-of select="$content"/>
       
   760 						</xsl:copy>
       
   761 					</xsl:if>
       
   762 				</xsl:when>
       
   763 				<xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise>
       
   764 			</xsl:choose>
       
   765 		</xsl:if>
       
   766 	</xsl:if>
       
   767 </xsl:template>
       
   768 
       
   769 <!-- /filters -->
       
   770 
       
   771 <!-- ======= rules to merge various aux data ============== -->
       
   772 <xsl:template match="*" mode="merge-attributes"/>
       
   773 <xsl:template match="*" mode="merge-content"/>
       
   774 
       
   775 
       
   776 <xsl:template match="/values" mode="merge-attributes"><xsl:param name="cmp"/><xsl:param name="base"/>
       
   777 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   778 		<xsl:if test="$base[@type!='style' and @type!='color']"> <!-- style and colour can have any number of values, so it needs to be captured in an element -->
       
   779 			<xsl:variable name="join"><xsl:if test="$base/@type!=''">-</xsl:if></xsl:variable>
       
   780 			<xsl:variable name="value" select="key('named',$cmp/@name)[self::component]/.."/>
       
   781 			<xsl:if test="$value/@value">
       
   782 				<xsl:attribute name="generator{$join}{$base/@type}">
       
   783 					<xsl:apply-templates select="$value" mode="style-id">
       
   784 						<xsl:with-param select="$base" name="base"/>
       
   785 					</xsl:apply-templates>
       
   786 				</xsl:attribute>
       
   787 			</xsl:if>
       
   788 		</xsl:if>
       
   789 	</xsl:if>
       
   790 </xsl:template>
       
   791 
       
   792 <xsl:template match="/values" mode="merge-content"><xsl:param name="cmp"/><xsl:param name="base"/>
       
   793 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   794 		<xsl:if test="$base[@type='style' or @type='color']"> <!-- at this point, only style and color can have multiple values -->
       
   795 			<xsl:variable name="join"><xsl:if test="$base/@type!=''">-</xsl:if></xsl:variable>
       
   796 			<xsl:variable name="value" select="key('named',$cmp/@name)[self::component]/.."/>
       
   797 			<xsl:choose>
       
   798 				<xsl:when test="$value">
       
   799 					<xsl:for-each select="$value">
       
   800 						<xsl:element name="generator{$join}{$base/@type}">
       
   801 						 	<xsl:attribute name="ref">
       
   802 								<xsl:apply-templates select="." mode="style-id">
       
   803 									<xsl:with-param select="$base" name="base"/>
       
   804 								</xsl:apply-templates>
       
   805 							</xsl:attribute>
       
   806 						</xsl:element>
       
   807 					</xsl:for-each>
       
   808 				</xsl:when>
       
   809 				<xsl:when test="@default">
       
   810 					<xsl:element name="generator{$join}{$base/@type}">
       
   811 					 	<xsl:attribute name="ref">
       
   812 							<xsl:apply-templates select="$base" mode="style-id"/>
       
   813 						</xsl:attribute>
       
   814 					</xsl:element>
       
   815 				</xsl:when>
       
   816 			</xsl:choose>
       
   817 		</xsl:if>
       
   818 	</xsl:if>
       
   819 </xsl:template>
       
   820 
       
   821 
       
   822 <!-- unsupported proprietary format -->
       
   823 <xsl:template match="/techstreams" mode="merge-attributes"><xsl:param name="cmp"/>
       
   824 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   825 		<xsl:attribute name="ts"><xsl:value-of select="key('named',$cmp/@name)[name()='component' and not(@type)]/../@name"/></xsl:attribute>
       
   826 	</xsl:if>
       
   827 </xsl:template>
       
   828 
       
   829 <xsl:template match="/techstreams" mode="merge-content"><xsl:param name="cmp"/>
       
   830 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   831 		<xsl:for-each select="key('named',$cmp/@name)[name()='component']">
       
   832 			<xsl:for-each select="self::component[not(@type)]/ancestor::group">
       
   833 				<ts-group><xsl:copy-of select="@*"/></ts-group>
       
   834 			</xsl:for-each>	
       
   835 			<xsl:for-each select="owners">
       
   836 				<xsl:copy><xsl:copy-of select="@*"/>
       
   837 					<xsl:if test="@type"><xsl:attribute name="ts"><xsl:value-of select="../../@name"/></xsl:attribute></xsl:if>
       
   838 				<xsl:copy-of select="*"/>
       
   839 				</xsl:copy>
       
   840 			</xsl:for-each>	
       
   841 		</xsl:for-each>	
       
   842 	</xsl:if>
       
   843 </xsl:template>
       
   844 
       
   845 <!-- unsupported proprietary format -->
       
   846 <xsl:template match="/attributes" mode="merge-attributes"><xsl:param name="cmp"/>
       
   847 	<xsl:for-each select="key('named',$cmp/ancestor::layer/@name)[self::layer and @inherit='yes']">
       
   848 		<xsl:copy-of select="attrs/@*"/>
       
   849 	</xsl:for-each>
       
   850 	<xsl:for-each select="key('named',$cmp/ancestor::block/@name)[self::block and @inherit='yes']">
       
   851 		<xsl:copy-of select="attrs/@*"/>
       
   852 	</xsl:for-each>
       
   853 	<xsl:for-each select="key('named',$cmp/ancestor::subblock/@name)[self::subblock and @inherit='yes']">
       
   854 		<xsl:copy-of select="attrs/@*"/>
       
   855 	</xsl:for-each>
       
   856 	<xsl:for-each select="key('named',$cmp/ancestor::collection/@name)[self::coll and @inherit='yes']">
       
   857 		<xsl:copy-of select="attrs/@*"/>
       
   858 	</xsl:for-each>
       
   859 	<xsl:for-each select="key('named',$cmp/@name)[starts-with(local-name($cmp),local-name())]">
       
   860 		<xsl:if test="not(@location) or (@location=$cmp/../@name)">
       
   861 			<xsl:copy-of select="attrs/@*"/>
       
   862 		</xsl:if>
       
   863 	</xsl:for-each>
       
   864 </xsl:template>
       
   865 <xsl:template match="/attributes" mode="merge-content"/>
       
   866 
       
   867 
       
   868 
       
   869 <xsl:template match="/model" mode="merge-attributes"><xsl:param name="cmp"/>
       
   870 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   871 		<!-- only use location if there is ambiguity -->
       
   872 		<xsl:variable name="loc">
       
   873 			<xsl:variable name="name" select="$cmp/@name"/>
       
   874 			<xsl:if test="count($cmp/ancestor::systemModel//component[@name=$name])!=1">
       
   875 				<xsl:for-each select="$cmp"><xsl:call-template name="location"/></xsl:for-each>
       
   876 			</xsl:if>
       
   877 		</xsl:variable>
       
   878 	<!--	<xsl:copy-of select="key('named',$cmp/@name)[name()='c' and ($loc='' or location=$loc)]/@*"/>-->
       
   879 		<xsl:for-each select="key('named',$cmp/@name)[name()='c' and ($loc='' or location=$loc)]/@*">
       
   880 			<xsl:copy-of select="."/>
       
   881 			<xsl:if test="name()='introduced'">   <!-- keep this while still in beta -->
       
   882 				<xsl:attribute name="since"><xsl:value-of select="."/></xsl:attribute>
       
   883 			</xsl:if>
       
   884 		</xsl:for-each>
       
   885 	</xsl:if>
       
   886 </xsl:template>
       
   887 
       
   888 <xsl:template match="/model" mode="merge-content"><xsl:param name="cmp"/>
       
   889 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   890 		<xsl:variable name="loc">
       
   891 			<xsl:variable name="name" select="$cmp/@name"/>
       
   892 			<xsl:if test="count($cmp/ancestor::systemModel//component[@name=$name])!=1">
       
   893 				<xsl:for-each select="$cmp"><xsl:call-template name="location"/></xsl:for-each>
       
   894 			</xsl:if>
       
   895 		</xsl:variable>
       
   896 		<xsl:for-each select="key('named',$cmp/@name)[name()='c' and ($loc='' or location=$loc)]">
       
   897 			<xsl:copy-of select="*[name()!='location' and name()!='bld' and name()!='ts']"/>
       
   898 			<xsl:apply-templates select="bld" mode="merge"/>
       
   899 		</xsl:for-each>
       
   900 	</xsl:if>
       
   901 </xsl:template>
       
   902 	
       
   903 
       
   904 <xsl:template match="/SQL" mode="merge-content"><xsl:param name="cmp"/>
       
   905 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   906 		<xsl:variable name="loc"><xsl:for-each select="$cmp"><xsl:call-template name="location"/></xsl:for-each></xsl:variable>
       
   907 		<xsl:for-each select="//ROW[translate(component,'&AZ;','&az;')=translate($cmp/name,'&AZ;','&az;')]">
       
   908 			<xsl:variable name="match">
       
   909 				<xsl:if test="layer"><xsl:value-of select="layer"/>/</xsl:if>
       
   910 				<xsl:if test="layer"><xsl:value-of select="block"/>/</xsl:if>
       
   911 				<xsl:if test="layer"><xsl:value-of select="subblock"/>/</xsl:if>
       
   912 				<xsl:if test="layer"><xsl:value-of select="collection"/>/</xsl:if>
       
   913 			</xsl:variable>
       
   914 			<xsl:if test="$match = concat($loc,'/') or 1 "><xsl:apply-templates mode="sql" select="*"/></xsl:if>
       
   915 		</xsl:for-each>
       
   916 	</xsl:if>
       
   917 </xsl:template>
       
   918 
       
   919 <xsl:template mode="sql" match="*"><xsl:copy-of select="."/></xsl:template>
       
   920 <xsl:template mode="sql" match="layer|block|subblock|collection|component"/>
       
   921 
       
   922 
       
   923 <xsl:template match="/Schedule12" mode="merge-content"><xsl:param name="cmp"/>
       
   924 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   925 		<xsl:variable name="match">
       
   926 			<xsl:call-template name="merge-Schedule12">
       
   927 				<xsl:with-param name="cmp" select="$cmp"/>
       
   928 			</xsl:call-template>
       
   929 		</xsl:variable>
       
   930 		<xsl:if test="$match='' ">
       
   931 			<xsl:call-template name="Caller-Warning"><xsl:with-param name="text"><xsl:value-of select="$cmp/@name"/> not in Schedule 12</xsl:with-param></xsl:call-template>
       
   932 		</xsl:if>
       
   933 		<xsl:if test="$match!='' ">
       
   934 			<xsl:apply-templates select="//system_model[$match=@entry]/.." mode="merge"/>
       
   935 		</xsl:if>
       
   936 	</xsl:if>
       
   937 </xsl:template>
       
   938 
       
   939 <xsl:template name="merge-Schedule12"><xsl:param name="path"/><xsl:param name="cmp"/>
       
   940 	<xsl:choose>
       
   941 	<!--  match this, then try matching parents -->
       
   942 		<xsl:when test="//system_model[@entry=$cmp/@name]">
       
   943 			<xsl:value-of select="$cmp/@name"/>
       
   944 		</xsl:when>
       
   945 		<xsl:when test="$cmp/parent::*[@name]">
       
   946 			<xsl:call-template name="merge-Schedule12">
       
   947 				<xsl:with-param name="cmp" select="$cmp/parent::*"/>
       
   948 			</xsl:call-template>			
       
   949 		</xsl:when>
       
   950 	</xsl:choose>
       
   951 </xsl:template>
       
   952 
       
   953 <xsl:template match="/LicensesFile" mode="merge-content"><xsl:param name="cmp"/>
       
   954 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   955 		<xsl:for-each select="//Supplier/Contract">
       
   956 			<xsl:variable name="n" select="@name"/>
       
   957 			<xsl:variable name="s" select="../@name"/>
       
   958 			<xsl:if test="not(following-sibling::Contract[@name=$n])">
       
   959 			<xsl:for-each select="$cmp/*[@name]"> <!-- if there is somthing without a contract use Symbian_Default -->
       
   960 				<xsl:if test="(not(@contract) and $n='Symbian_Default') or @contract=$n"><supplier name="{$s}" for="{@name}"/></xsl:if>
       
   961 			</xsl:for-each>
       
   962 			</xsl:if>
       
   963 		</xsl:for-each>
       
   964 	</xsl:if>
       
   965 </xsl:template>
       
   966 
       
   967 
       
   968 <xsl:template match="/SystemModelDeps" mode="merge-content"><xsl:param name="cmp"/>
       
   969 	<xsl:if test="$cmp[self::component]"> <!-- only valid for components -->
       
   970 		<Build>
       
   971 			<xsl:variable name="name">
       
   972 				<xsl:choose>
       
   973 					<xsl:when test="starts-with(@component,'techview_')"><xsl:message/><xsl:value-of select="substring-after(@component,'techview_')"/></xsl:when>
       
   974 					<xsl:otherwise><xsl:value-of select="@component"/></xsl:otherwise>
       
   975 				</xsl:choose>
       
   976 			</xsl:variable>
       
   977 			<xsl:apply-templates select="//Executable[$cmp/@name=@component or ($cmp/*[contains(@filter,'techview')] and concat('techview_',$cmp/@name)=@component)]"/>
       
   978 		</Build>
       
   979 	</xsl:if>
       
   980 </xsl:template>
       
   981 <!-- /aux rules -->
       
   982 
       
   983 <xsl:template match="@root" mode="merge-attributes"/>
       
   984 <xsl:template match="@root" mode="merge-content"/>
       
   985 
       
   986 <xsl:template match="@*" mode="merge-attributes"><xsl:param name="cmp"/>
       
   987 	<xsl:apply-templates mode="merge-attributes" select="document(.,/)/*">
       
   988 		<xsl:with-param name="cmp" select="$cmp"/>		
       
   989 	</xsl:apply-templates>
       
   990 </xsl:template>
       
   991 
       
   992 <xsl:template match="info[@type!='symsym']" mode="merge-attributes"><xsl:param name="cmp"/> 
       
   993 	<!-- not called for symsym snice symsym only adds components -->
       
   994 	<xsl:apply-templates mode="merge-attributes" select="document(@href,/)/*">
       
   995 		<xsl:with-param name="cmp" select="$cmp"/>
       
   996 		<xsl:with-param name="base" select="."/>
       
   997 	</xsl:apply-templates>
       
   998 </xsl:template>
       
   999 
       
  1000 <xsl:template match="@*" mode="merge-content"><xsl:param name="cmp"/>
       
  1001 	<xsl:apply-templates mode="merge-content" select="document(.,/)/*">
       
  1002 		<xsl:with-param name="cmp" select="$cmp"/>
       
  1003 	</xsl:apply-templates>
       
  1004 </xsl:template>
       
  1005 
       
  1006 <xsl:template match="info" mode="merge-content"><xsl:param name="cmp"/>
       
  1007 	<xsl:apply-templates mode="merge-content" select="document(@href,/)/*">
       
  1008 		<xsl:with-param name="cmp" select="$cmp"/>		
       
  1009 		<xsl:with-param name="base" select="."/>
       
  1010 	</xsl:apply-templates>
       
  1011 </xsl:template>
       
  1012 
       
  1013 <xsl:template match="info[@type='symsym']" mode="merge-content"><xsl:param name="cmp"/>
       
  1014 	<xsl:variable name="filter" select="@dbfilter"/>
       
  1015 	<xsl:variable name="use" select="@use"/>
       
  1016 	<xsl:variable name="include" select="concat(',',@include,',')"/>
       
  1017 	<SQL>
       
  1018 		<xsl:for-each select="document(@href)/SQL/ROW/*[name()=$filter]">
       
  1019 			<xsl:variable name="name" select="translate(.,'&AZ;','&az;')"/>
       
  1020 			<xsl:if test="($use='mrp' and $cmp/*[translate(@name,'&AZ;','&az;')=$name]) or ($use='component' and translate($cmp/@name,'&AZ;','&az;')=$name)">
       
  1021 			 	<xsl:for-each select="..">
       
  1022 					<xsl:copy>
       
  1023 						<xsl:for-each select="*">
       
  1024 							<xsl:if test="$include=',,' or contains($include,concat(',',name(),','))"><xsl:copy-of select="."/></xsl:if>
       
  1025 						</xsl:for-each>
       
  1026 					</xsl:copy>
       
  1027 				</xsl:for-each>
       
  1028 			</xsl:if>
       
  1029 		</xsl:for-each>
       
  1030 	</SQL>
       
  1031 </xsl:template>
       
  1032 
       
  1033 <xsl:template match="component" mode="merge"><xsl:param name="extra-files"/>
       
  1034 	<xsl:variable name="e"><xsl:call-template name="is-present"/></xsl:variable>
       
  1035 	<xsl:if test="$e!=''">
       
  1036 		<xsl:copy><xsl:copy-of select="@*"/>
       
  1037 			<xsl:if test="$Origin-attr!='' and not(@*[local-name()=$Origin-attr]) and /SystemDefinition/@name!=''">
       
  1038 				<xsl:attribute name="{$Origin-attr}">	<!-- indicate which model this came from -->
       
  1039 					<xsl:value-of select="/SystemDefinition/@name"/>
       
  1040 				</xsl:attribute>
       
  1041 			</xsl:if>
       
  1042 			<xsl:apply-templates select="$extra-files" mode="merge-attributes">
       
  1043 				<xsl:with-param name="cmp" select="."/>			
       
  1044 			</xsl:apply-templates>
       
  1045 			<xsl:call-template name="abbrev"/>	
       
  1046 			<xsl:apply-templates select="$extra-files" mode="merge-content">
       
  1047 				<xsl:with-param name="cmp" select="."/>
       
  1048 			</xsl:apply-templates>
       
  1049 			<xsl:apply-templates select="*" mode="merge">
       
  1050 				<xsl:with-param name="extra-files" select="$extra-files"/>
       
  1051 			</xsl:apply-templates>	 
       
  1052 		</xsl:copy>
       
  1053 	</xsl:if>
       
  1054 </xsl:template>
       
  1055 
       
  1056 
       
  1057 <xsl:template match="component/*" mode="merge"><xsl:param name="extra-files"/>
       
  1058 <xsl:variable name="e"><xsl:call-template name="is-present"/></xsl:variable>
       
  1059 <xsl:if test="$e!=''">
       
  1060 		<xsl:copy><xsl:copy-of select="@*"/> <!-- only put root attribute on units with a path in them - does not make sense otherwise -->
       
  1061 		<xsl:if test="not(@root) and (@mrp or @bldFile)"><xsl:copy-of select="$extra-files[name()='root']"/></xsl:if>
       
  1062 		<xsl:copy-of select="node()"/>
       
  1063 	</xsl:copy>
       
  1064 	</xsl:if>
       
  1065 </xsl:template>
       
  1066 
       
  1067 <xsl:template name="abbrev">
       
  1068 	<xsl:variable name="n" select="@name"/>
       
  1069 	<xsl:variable name="match" select="$abbrevs[@name=$n]"/>
       
  1070 	<xsl:choose>
       
  1071 		<xsl:when test="not($match)"/>
       
  1072 		<xsl:when test="self::techstream">
       
  1073 			<xsl:attribute name="label"><xsl:value-of select="$match/@abbrev"/></xsl:attribute>
       
  1074 		</xsl:when>
       
  1075 	<!-- 	<xsl:when test="self::component">
       
  1076 			<name><xsl:copy-of select="$match/@font|$match/../@font"/><xsl:value-of select="$match/@abbrev"/></name>
       
  1077 		</xsl:when>-->
       
  1078 		<xsl:otherwise><xsl:copy-of select="$match/@abbrev|$match/@font|$match/../@font"/></xsl:otherwise>
       
  1079 	</xsl:choose>
       
  1080 </xsl:template>
       
  1081 
       
  1082 <xsl:template name="location">
       
  1083 	<xsl:if test="../../@name"><xsl:for-each select="parent::*[@name]"><xsl:call-template name="location"/>/</xsl:for-each></xsl:if>
       
  1084 	<xsl:if test="../@name"><xsl:value-of select="../@name"/></xsl:if>
       
  1085 </xsl:template>
       
  1086 
       
  1087 <xsl:template match="Executable">
       
  1088 	<Bin><xsl:copy-of select="@*[name()!='component']|*"/></Bin>
       
  1089 </xsl:template>
       
  1090 
       
  1091 <!-- /merge model with extra -->
       
  1092 
       
  1093 <!-- merge logo -->
       
  1094 <xsl:template match="layout/logo" mode="merge">
       
  1095 	<xsl:copy><xsl:copy-of select="@width | @height"/>
       
  1096 	<xsl:choose>
       
  1097 		<xsl:when test="@embed='yes' or @embed='true' ">
       
  1098 			<xsl:for-each select="document(@src,.)/s:svg">
       
  1099 				<xsl:copy-of select="@viewBox"/>
       
  1100 				<xsl:copy-of select="*"/>
       
  1101 			</xsl:for-each>
       
  1102 		</xsl:when>
       
  1103 		<xsl:otherwise><xsl:copy-of select="@src"/></xsl:otherwise>
       
  1104 	</xsl:choose>
       
  1105 	</xsl:copy>
       
  1106 </xsl:template>
       
  1107 
       
  1108 <!-- merge legend -->
       
  1109 <xsl:template match="layout/legend" mode="merge">
       
  1110 	<legend-layer><xsl:copy-of select="@*[name()!='literal']"/>
       
  1111 		<xsl:if test="not(@literal='yes' or @literal='true') and contains(@label,'{')">
       
  1112 			<xsl:attribute name="label-ref"><xsl:apply-templates mode="style-id" select="."/></xsl:attribute>
       
  1113 		</xsl:if>	
       
  1114 	<!-- only draw footer items if they are not referenced elsewhere in a label -->
       
  1115 		<xsl:variable name="footer">
       
  1116 			<xsl:for-each select="/model/@copyright|/model/@distribution">
       
  1117 				<xsl:variable name="a" select="concat('@',name())"/>
       
  1118 				<xsl:if test="not(/model/layout//legend[contains(@label,$a)]) and not(/model/layout//legend/note[contains(.,$a)])">
       
  1119 					<xsl:value-of select="concat(name(),' ')"/>
       
  1120 				</xsl:if>
       
  1121 			</xsl:for-each>
       
  1122 		</xsl:variable>
       
  1123 		<xsl:if test="$footer!=''"><xsl:attribute name="footer"><xsl:value-of select="normalize-space($footer)"/></xsl:attribute></xsl:if>
       
  1124 		<xsl:apply-templates select="*" mode="merge"/>
       
  1125 	</legend-layer>
       
  1126 </xsl:template>
       
  1127 
       
  1128 <xsl:template match="legend" mode="merge">
       
  1129 	<xsl:copy>
       
  1130 		<xsl:copy-of select="@*[name()!='literal']"/>
       
  1131 		<xsl:if test="not(@literal='yes' or @literal='true') and contains(@label,'{')">
       
  1132 			<xsl:attribute name="label-ref"><xsl:apply-templates mode="style-id" select="."/></xsl:attribute>
       
  1133 		</xsl:if>	
       
  1134 		<xsl:apply-templates select="*" mode="merge"/>
       
  1135 	</xsl:copy>
       
  1136 </xsl:template>
       
  1137 
       
  1138 <xsl:template match="legend/note|legend/s:svg" mode="merge">
       
  1139 	<xsl:copy><xsl:copy-of select="@*[name()!='literal']"/>
       
  1140 		<xsl:if test="self::note and not(@literal='yes' or @literal='true') and contains(.,'{')">
       
  1141 			<xsl:attribute name="label-ref"><xsl:apply-templates mode="style-id" select="."/></xsl:attribute>
       
  1142 		</xsl:if>
       
  1143 		<xsl:copy-of select="node()"/>
       
  1144 	</xsl:copy>
       
  1145 </xsl:template>
       
  1146 
       
  1147 <xsl:template match="cmp" mode="merge"><xsl:param name="model"/>
       
  1148 	<xsl:copy>
       
  1149 		<xsl:apply-templates select="@*" mode="generated-value">
       
  1150 			<xsl:with-param name="model" select="$model"/>		
       
  1151 		</xsl:apply-templates>
       
  1152 		<xsl:if test="not(@literal='yes' or @literal='true') and contains(.,'{')">
       
  1153 			<xsl:attribute name="label-ref"><xsl:apply-templates mode="style-id" select="."/></xsl:attribute>
       
  1154 		</xsl:if>
       
  1155 		<xsl:copy-of select="text()"/>
       
  1156 	</xsl:copy>
       
  1157 </xsl:template>
       
  1158 
       
  1159 <!--not sure if this bit is actually used anywhere -->
       
  1160 <xsl:template match="@*" mode="generated-value"/>
       
  1161 <xsl:template match="@overlay|@border|@style" mode="generated-value">
       
  1162 	<xsl:variable name="n" select="name()"/>
       
  1163 	<xsl:variable name="v" select="."/>
       
  1164 	<xsl:variable name="m" select="//*[name()=$n and @label=$v]"/>
       
  1165 	<xsl:if test="count($m)">
       
  1166 		<xsl:attribute name="generator-{$n}">
       
  1167 			<xsl:apply-templates select="$m" mode="style-id"/>
       
  1168 		</xsl:attribute>
       
  1169 	</xsl:if>
       
  1170 </xsl:template>
       
  1171 <!--not sure if this bit is actually used anywhere -->
       
  1172 <xsl:template match="@color" mode="generated-value"><xsl:param name="model"/>
       
  1173 	<xsl:variable name="v" select="."/>
       
  1174 	<xsl:variable name="m" select="//color[@label=$v]"/>
       
  1175 	<xsl:choose>
       
  1176 		<xsl:when test="count($m)">
       
  1177 			<xsl:attribute name="generator-color"><xsl:apply-templates select="$m" mode="style-id"/></xsl:attribute>
       
  1178 		</xsl:when>
       
  1179 		<xsl:when test="$model//info[@type='color']">
       
  1180 			<xsl:attribute name="generator-color">
       
  1181 				<xsl:variable name="m0" select="$model//info[@type='color']/@href"/>
       
  1182 				<xsl:apply-templates select="document($m0/@href,$m0)//item[@label=$v]" mode="style-id">
       
  1183 					<xsl:with-param name="base" select="$m0"/>
       
  1184 				</xsl:apply-templates>
       
  1185 			</xsl:attribute>
       
  1186 		</xsl:when>		
       
  1187 		<xsl:when test="//colors[not(*) and @match='@ts']">
       
  1188 			<xsl:variable name="id"><xsl:apply-templates select="//colors[not(*) and @match='@ts']" mode="style-id"/></xsl:variable>
       
  1189 			<xsl:for-each select="document($model/@ts)//techstream[@name=$v]">
       
  1190 				<xsl:attribute name="generator-color"><xsl:value-of select="concat($id,'-color',count(preceding::techstream))"/></xsl:attribute>
       
  1191 			</xsl:for-each>
       
  1192 		</xsl:when>
       
  1193 	</xsl:choose>
       
  1194 </xsl:template>
       
  1195 
       
  1196 <xsl:template match="title" mode="merge"><xsl:copy-of select="."/></xsl:template>
       
  1197 <xsl:template match="ts" mode="merge"><cbox><xsl:copy-of select="@*|node()"/></cbox></xsl:template>
       
  1198 
       
  1199 <xsl:template match="legend[s:g]" mode="merge">
       
  1200 <xsl:copy-of select="."/>
       
  1201 </xsl:template>
       
  1202 
       
  1203 <xsl:template match="legend" mode="copy">
       
  1204 	<xsl:copy-of select="@*[name()!='use' or name()='literal']"/>
       
  1205 	<xsl:if test="not(@literal='yes' or @literal='true') and contains(@label,'{')">
       
  1206 		<xsl:attribute name="label-ref"><xsl:apply-templates mode="style-id" select="."/></xsl:attribute>
       
  1207 	</xsl:if>	
       
  1208 </xsl:template>
       
  1209 
       
  1210 <xsl:template match="legend[@use]" mode="merge">
       
  1211 	
       
  1212 	<!-- 	$tag = bit after the # (can be empty)
       
  1213 		$pre is bit before the # (can be empty)
       
  1214 		$file is file pointed to by pre (can be empty) -->
       
  1215 
       
  1216 	<xsl:variable name="tag" select="substring-after(@use,'#')"/>
       
  1217 	<xsl:variable name="pre">
       
  1218 		<xsl:choose>
       
  1219 			<xsl:when test="$tag!=''"><xsl:value-of select="substring-before(@use,'#')"/></xsl:when>
       
  1220 			<xsl:otherwise><xsl:value-of select="@use"/></xsl:otherwise>
       
  1221 		</xsl:choose>
       
  1222 	</xsl:variable>
       
  1223 
       
  1224 	<xsl:variable name="file">
       
  1225 		<xsl:choose>
       
  1226 			<xsl:when test="starts-with($pre,'@')"><xsl:value-of select="//model/@*[name()=substring($pre,2)]"/></xsl:when>
       
  1227 			<xsl:otherwise><xsl:value-of select="$pre"/></xsl:otherwise>
       
  1228 		</xsl:choose>
       
  1229 	</xsl:variable>
       
  1230 	
       
  1231 	<xsl:variable name="model" select="/model"/>  <!--  hack for xsltproc -->
       
  1232 	<xsl:variable name="legend" select="."/>  <!--  hack for xsltproc -->
       
  1233 
       
  1234 	<xsl:variable name="this" select="."/>  <!--  save node just in case need to use more than once -->
       
  1235 
       
  1236 	
       
  1237 	<xsl:choose>
       
  1238 		<xsl:when test="$tag!='' and $pre=''">
       
  1239 			<!-- pre is empty, but tag is not, so this legend is an info in this file -->
       
  1240 			<xsl:for-each select="ancestor::layout/info[@type=$tag]">
       
  1241 				<legend>
       
  1242 					<xsl:apply-templates select="$this" mode="copy"/>
       
  1243 					<xsl:apply-templates select="." mode="merge">
       
  1244 						<xsl:with-param name="model" select="$model"/>
       
  1245 						<xsl:with-param name="legend" select="$legend"/>
       
  1246 					</xsl:apply-templates>
       
  1247 				</legend>
       
  1248 			</xsl:for-each>
       
  1249 		</xsl:when>
       
  1250 		<xsl:when test="$tag!=''">
       
  1251 			<xsl:for-each select="document($file,/)/*/*[name()=$tag]">
       
  1252 				<legend>
       
  1253 					<xsl:apply-templates select="$this" mode="copy"/>
       
  1254 					<xsl:apply-templates select="." mode="merge">
       
  1255 						<xsl:with-param name="model" select="$model"/>
       
  1256 						<xsl:with-param name="legend" select="$legend"/>
       
  1257 					</xsl:apply-templates>
       
  1258 				</legend>			
       
  1259 			</xsl:for-each>
       
  1260 		</xsl:when>
       
  1261 		<xsl:otherwise>
       
  1262 			<xsl:for-each select="document($file,/)/*">
       
  1263 				<legend>
       
  1264 					<xsl:apply-templates select="$this" mode="copy"/>
       
  1265 					<xsl:apply-templates select="." mode="merge">
       
  1266 						<xsl:with-param name="model" select="$model"/>
       
  1267 						<xsl:with-param name="legend" select="$legend"/>
       
  1268 					</xsl:apply-templates>
       
  1269 				</legend>			
       
  1270 			</xsl:for-each>			
       
  1271 			</xsl:otherwise>
       
  1272 	</xsl:choose>
       
  1273 </xsl:template>
       
  1274 
       
  1275 <xsl:template match="info[(@type='color'  or @type='overlay' or @type='style' or @type='border') and document(@href,.)/values]" mode="merge">
       
  1276 	<xsl:attribute name="use"><xsl:apply-templates select="." mode="style-id"/></xsl:attribute>
       
  1277 	<xsl:attribute name="type">
       
  1278 		<xsl:choose>
       
  1279 			<xsl:when test="@type='color'">cbox</xsl:when>
       
  1280 			<xsl:otherwise>cmp</xsl:otherwise>
       
  1281 		</xsl:choose>
       
  1282 	</xsl:attribute>
       
  1283 </xsl:template>
       
  1284 
       
  1285 <xsl:template match="text()" mode="merge"/>
       
  1286 
       
  1287 <!-- Any ref with a type attribute that starts with a # indicates a literal ref, so just copy it -->
       
  1288 <xsl:template match="*[starts-with(@type,'#')]" mode="ref" priority="1"><xsl:value-of select="@type"/></xsl:template>
       
  1289 
       
  1290 <!-- Borders in legend -->
       
  1291 
       
  1292 <xsl:template match="border" mode="ref">#Border<xsl:choose>
       
  1293 		<xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
       
  1294 		<xsl:otherwise>Shape<xsl:value-of select="count(preceding::border)"/></xsl:otherwise>
       
  1295 	</xsl:choose>
       
  1296 </xsl:template>
       
  1297 
       
  1298 <xsl:template match="color[../@type='highlight' or ../@type='text-highlight']" mode="ref">
       
  1299 	<xsl:value-of select="concat('#',../@type,count(preceding::color[../@type]))"/>
       
  1300 </xsl:template>
       
  1301 
       
  1302 <!-- Colours in legend -->
       
  1303 
       
  1304 <xsl:template match="/shapes/colors/color[not(@value|@label)]" mode="merge" priority="3"/> 	<!-- use value if no label, but don't show if neither -->
       
  1305 
       
  1306 
       
  1307 <!-- can have any number of these, so put in a sub-legend -->
       
  1308 <xsl:template match="/shapes/examples" mode="merge"><xsl:param name="model"/>
       
  1309 	<xsl:param name="legend"/>	<!-- label on legend overrides label in values document -->
       
  1310 	<xsl:variable name="tag" select="name()"/>
       
  1311 	<xsl:variable name="content">
       
  1312 		<!-- don't show this label if there is a label defined in the Model XML doc *and* this is the first legend item of this type (e.g colors, styles, etc)	 -->
       
  1313 		<xsl:choose>
       
  1314 			<xsl:when test="@sort='yes'">
       
  1315 				<xsl:apply-templates mode="merge">
       
  1316 					<xsl:sort select="@label"/>
       
  1317 					<xsl:with-param name="model" select="$model"/>
       
  1318 				</xsl:apply-templates>
       
  1319 			</xsl:when>
       
  1320 			<xsl:otherwise>
       
  1321 				<xsl:apply-templates mode="merge"><xsl:with-param name="model" select="$model"/></xsl:apply-templates>
       
  1322 			</xsl:otherwise>
       
  1323 		</xsl:choose>
       
  1324 	</xsl:variable>
       
  1325 	<xsl:choose>
       
  1326 		<xsl:when test="count(//*[name()=$tag]) != 1">
       
  1327 			<legend>
       
  1328 				<xsl:if test="not($legend) or not($legend/@label) or preceding-sibling::*[name()=$tag]"><xsl:apply-templates select="@label"  mode="legend-abbrev"/></xsl:if>
       
  1329 				<xsl:copy-of select="$content"/>
       
  1330 			</legend>
       
  1331 		</xsl:when>
       
  1332 		<xsl:otherwise>
       
  1333 			<xsl:copy-of select="@sort|@show-unused"/>
       
  1334 			<xsl:if test="not($legend) or not($legend/@label) or preceding-sibling::*[name()=$tag]"><xsl:apply-templates select="@label"  mode="legend-abbrev"/></xsl:if>
       
  1335 			<xsl:copy-of select="$content"/></xsl:otherwise>
       
  1336 	</xsl:choose>
       
  1337 </xsl:template>
       
  1338 
       
  1339 <!-- can have any number of these, so put in a sub-legend -->
       
  1340 <xsl:template match="/shapes/styles|/shapes/colors|/shapes/patterns|/shapes/borders" mode="merge">
       
  1341 	<xsl:variable name="tag" select="name()"/>
       
  1342 
       
  1343 	
       
  1344 	<xsl:choose>
       
  1345 		<xsl:when test="count(//*[name()=$tag]) != 1">
       
  1346 			<legend>
       
  1347 				<xsl:copy-of select="@sort|@show-unused"/>
       
  1348 				<xsl:attribute name="use"><xsl:apply-templates select="." mode="style-id"/></xsl:attribute>		
       
  1349 				<xsl:attribute name="type">cmp</xsl:attribute>
       
  1350 			</legend>
       
  1351 		</xsl:when>
       
  1352 		<xsl:otherwise>
       
  1353 			<xsl:copy-of select="@sort|@show-unused"/>
       
  1354 			<xsl:attribute name="use"><xsl:apply-templates select="." mode="style-id"/></xsl:attribute>		
       
  1355 			<xsl:attribute name="type">cmp</xsl:attribute>		
       
  1356 		</xsl:otherwise>
       
  1357 	</xsl:choose>
       
  1358 
       
  1359 	
       
  1360 </xsl:template>
       
  1361 
       
  1362 
       
  1363 <xsl:template match="overlay" mode="ref">#Pattern<xsl:choose>
       
  1364 		<xsl:when test="@type"><xsl:value-of select="@type"/></xsl:when>
       
  1365 		<xsl:otherwise>Overlay<xsl:value-of select="count(preceding::overlay)"/></xsl:otherwise>
       
  1366 	</xsl:choose>
       
  1367 </xsl:template>
       
  1368 
       
  1369 	
       
  1370 <xsl:template match="/shapes/*/*[not(@label)]" mode="merge"/> <!--  don't show legend items with no label -->
       
  1371 	
       
  1372 
       
  1373 <xsl:template match="/shapes" mode="as-example"><xsl:param name="at"/>
       
  1374 	<xsl:choose>
       
  1375 		<xsl:when test="name($at)='border' or name($at)='overlay'">
       
  1376 			<xsl:attribute name="generator-{name($at)}">
       
  1377 				<xsl:apply-templates  select="//*[name()=name($at) and @label=$at]" mode="style-id"/>
       
  1378 			</xsl:attribute>
       
  1379 		</xsl:when>
       
  1380 		<xsl:when test="name($at)='style'">
       
  1381 			<xsl:attribute name="generator-{name($at)}"><xsl:apply-templates  select="//style[@label=$at]" mode="style-id"/></xsl:attribute>			
       
  1382 		</xsl:when>	
       
  1383 		<xsl:when test="name($at)='color-highlight'">
       
  1384 			<xsl:attribute name="generator-highlight">
       
  1385 				<xsl:apply-templates select="//colors[@type='highlight']/color[@label=$at]" mode="style-id"/>
       
  1386 			</xsl:attribute>
       
  1387 		</xsl:when>	
       
  1388 		<xsl:when test="name($at)='color-text-highlight'">
       
  1389 			<xsl:attribute name="generator-text-highlight">
       
  1390 				<xsl:apply-templates select="//colors[@type='text-highlight']/color[@label=$at]" mode="style-id"/>
       
  1391 			</xsl:attribute>
       
  1392 		</xsl:when>	
       
  1393 		<xsl:when test="name($at)='color'">
       
  1394 			<xsl:attribute name="generator-color">
       
  1395 				<xsl:apply-templates select="//colors[not(@type) or @type='background']/color[@label=$at]/@color" mode="style-id"/>
       
  1396 			</xsl:attribute>
       
  1397 		</xsl:when>	
       
  1398 	</xsl:choose>
       
  1399 </xsl:template>
       
  1400 
       
  1401 
       
  1402 <xsl:template match="examples/cmp" mode="merge"><xsl:param name="model"/><xsl:param name="shapes" select="/shapes"/>
       
  1403 	<cmp>
       
  1404 		<xsl:if test="not(@literal='yes' or @literal='true') and contains(.,'{')">
       
  1405 			<xsl:attribute name="label-ref"><xsl:apply-templates mode="style-id" select="."/></xsl:attribute>
       
  1406 		</xsl:if>	
       
  1407 		<xsl:for-each select="@*">
       
  1408 			<xsl:apply-templates select="$shapes" mode="as-example">
       
  1409 				<xsl:with-param name="at" select="."/>
       
  1410 			</xsl:apply-templates>
       
  1411 		</xsl:for-each>
       
  1412 		<xsl:apply-templates mode="generated-value" select="@color">
       
  1413 			<xsl:with-param name="model" select="$model"/>
       
  1414 		</xsl:apply-templates>
       
  1415 		<xsl:copy-of select="text()"/>
       
  1416 	</cmp>
       
  1417 </xsl:template>
       
  1418 
       
  1419 
       
  1420 <xsl:template match="/shapes/colors[not(*)]" mode="merge"><xsl:param name="model"/>
       
  1421 <!-- special known type which can be generated -->
       
  1422 	<xsl:choose>
       
  1423 		<xsl:when test="count(//colors) != 1 and @match='@ts' and $model">
       
  1424 			<legend>
       
  1425 				<xsl:attribute name="use"><xsl:apply-templates select="." mode="style-id"/></xsl:attribute>
       
  1426 				<xsl:attribute name="sort">yes</xsl:attribute>
       
  1427 				<xsl:attribute name="type">cbox</xsl:attribute>
       
  1428 			</legend>
       
  1429 		</xsl:when>
       
  1430 		<xsl:when test="@match='@ts' and $model">
       
  1431 			<xsl:attribute name="use"><xsl:apply-templates select="." mode="style-id"/></xsl:attribute>
       
  1432 			<xsl:attribute name="sort">yes</xsl:attribute>
       
  1433 			<xsl:attribute name="type">cbox</xsl:attribute>
       
  1434 		</xsl:when>
       
  1435 		<xsl:otherwise>
       
  1436 			<xsl:call-template name="Caller-Warning"><xsl:with-param name="text">no colour data</xsl:with-param></xsl:call-template>
       
  1437 		</xsl:otherwise>
       
  1438 	</xsl:choose>
       
  1439 </xsl:template>
       
  1440 
       
  1441 <!-- /merge legend -->
       
  1442 
       
  1443 <!-- new experimetal stuff  -->
       
  1444 <xsl:template match="node()" mode="styling"/>
       
  1445 
       
  1446 <xsl:template match="@shapes" mode="styling">
       
  1447 	<xsl:variable name="model" select=".."/> <!-- hack for xsltproc -->
       
  1448 	<xsl:apply-templates select="document(.,.)/shapes/*" mode="styling">
       
  1449 	<xsl:with-param name="model" select="$model"/>
       
  1450 	</xsl:apply-templates>
       
  1451 </xsl:template>
       
  1452 
       
  1453 
       
  1454 <xsl:template match="info" mode="style-id">
       
  1455 	<xsl:value-of select="concat('i',count(preceding-sibling::info))"/>
       
  1456 </xsl:template>
       
  1457 
       
  1458 
       
  1459 <xsl:template match="/values" mode="style-id"><xsl:param name="base"/>
       
  1460 	<xsl:apply-templates select="$base" mode="style-id"/>
       
  1461 </xsl:template>
       
  1462 
       
  1463 <xsl:template match="/values/item" mode="style-id"><xsl:param name="base"/>
       
  1464 	<xsl:apply-templates select="$base" mode="style-id"/>-<xsl:value-of select="name()"/>
       
  1465 	<xsl:value-of select="count(preceding-sibling::*)"/>
       
  1466 </xsl:template>
       
  1467 
       
  1468 <xsl:template match="colors|borders|patterns|styles" mode="style-id">
       
  1469 	<xsl:value-of select="concat('s',count(preceding-sibling::*))"/>
       
  1470 </xsl:template>
       
  1471 
       
  1472 <xsl:template match="examples/cmp" mode="style-id">
       
  1473 	<xsl:value-of select="concat('e',count(preceding::cmp[parent::examples]))"/>
       
  1474 </xsl:template>
       
  1475 	
       
  1476 
       
  1477 <xsl:template match="note" mode="style-id">
       
  1478 	<xsl:value-of select="concat('n',count(preceding::note))"/>
       
  1479 </xsl:template>
       
  1480 
       
  1481 <xsl:template match="legend" mode="style-id">
       
  1482 	<xsl:value-of select="concat('L',count(preceding::legend))"/>
       
  1483 </xsl:template>
       
  1484 
       
  1485 <xsl:template match="colors/color|borders/border|patterns/overlay|styles/style" mode="style-id">
       
  1486 	<xsl:apply-templates select=".." mode="style-id"/>-<xsl:value-of select="name()"/>
       
  1487 	<xsl:value-of select="count(preceding-sibling::*)"/>
       
  1488 </xsl:template>
       
  1489 
       
  1490 <xsl:template match="layout/info[@type='color' or @type='border' or @type='overlay' or @type='style']" mode="styling">
       
  1491 	<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>
       
  1492 	<xsl:variable name="base" select="."/>
       
  1493 	<group style-id="{$id}" detail="component">
       
  1494 		<xsl:copy-of select="@type | @show-unused"/>
       
  1495 		<xsl:for-each select="document(@href,.)/values">
       
  1496 			<xsl:copy-of select="@default"/>
       
  1497 			<xsl:apply-templates select="@label"  mode="legend-abbrev"/>				
       
  1498 			<xsl:for-each select="item">
       
  1499 				<xsl:variable name="el">
       
  1500 					<xsl:choose>
       
  1501 						<xsl:when test="$base/@type='color'">cbox</xsl:when>
       
  1502 						<xsl:otherwise>cmp</xsl:otherwise>
       
  1503 					</xsl:choose>
       
  1504 				</xsl:variable>
       
  1505 				<xsl:element name="{$el}">
       
  1506 					<xsl:attribute name="style-id">
       
  1507 						<xsl:apply-templates select="." mode="style-id">
       
  1508 							<xsl:with-param name="base" select="$base"/>
       
  1509 						</xsl:apply-templates>
       
  1510 					</xsl:attribute>
       
  1511 					<xsl:apply-templates select="@label"  mode="legend-abbrev"/>	
       
  1512 					<xsl:attribute name="value">
       
  1513 					<xsl:choose>
       
  1514 						<xsl:when test="not(starts-with(@value,'#')) and $base/@type='border' ">#Border<xsl:value-of select="@value"/></xsl:when> 
       
  1515 						<xsl:when test="not(starts-with(@value,'#')) and $base/@type='overlay' ">#Pattern<xsl:value-of select="@value"/></xsl:when>
       
  1516 							<!-- highlight not allowed in values files, but put here anyway -->
       
  1517 						<xsl:when test="contains($base/@type,'highlight')">#<xsl:value-of select="$base/@type"/>
       
  1518 							<xsl:apply-templates select="." mode="style-id">
       
  1519 								<xsl:with-param name="base" select="$base"/>
       
  1520 							</xsl:apply-templates></xsl:when>
       
  1521 						<xsl:otherwise><xsl:value-of select="@value"/></xsl:otherwise>
       
  1522 					</xsl:choose>
       
  1523 					</xsl:attribute>
       
  1524 				</xsl:element>
       
  1525 			</xsl:for-each>
       
  1526 		</xsl:for-each>
       
  1527 	</group>
       
  1528 </xsl:template>
       
  1529 
       
  1530 <xsl:template match="/shapes/colors[not(@type) or @type='background']" mode="styling"><xsl:param name="model"/>
       
  1531 	<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>
       
  1532 	<group type="color" style-id="{$id}">
       
  1533 		<xsl:copy-of select="@default"/>
       
  1534 		<xsl:call-template name="lgd-group-detail"/>
       
  1535 		<xsl:apply-templates select="@label"  mode="legend-abbrev"/>			
       
  1536 		<xsl:choose>
       
  1537 		<xsl:when test="not(*) and @match='@ts' and $model">
       
  1538 			<xsl:apply-templates select="document($model/@ts,$model)/*" mode="styling">
       
  1539 				<xsl:with-param name="id" select="$id"/>
       
  1540 			</xsl:apply-templates>
       
  1541 		</xsl:when>
       
  1542 		<xsl:otherwise>
       
  1543 			<xsl:apply-templates mode="styling"><xsl:with-param name="id" select="$id"/></xsl:apply-templates>
       
  1544 		</xsl:otherwise>
       
  1545 		</xsl:choose>
       
  1546 	</group>
       
  1547 </xsl:template>
       
  1548 
       
  1549 <xsl:template name="lgd-group-detail">
       
  1550 	<xsl:choose>
       
  1551 		<xsl:when test="self::borders or self::patterns or  not(@match)"><xsl:attribute name="detail">component</xsl:attribute></xsl:when>
       
  1552 		<xsl:when test="@match='component' or @match='collection' or @match='block' or @match='subblock' or @match='layer'">
       
  1553 			<xsl:attribute name="detail"><xsl:value-of select="@match"/></xsl:attribute>
       
  1554 		</xsl:when>
       
  1555 	</xsl:choose>
       
  1556 </xsl:template>
       
  1557 
       
  1558 <xsl:template match="@label" mode="legend-abbrev">
       
  1559 	<xsl:variable name="n" select="."/>
       
  1560 	<xsl:variable name="match" select="$abbrevs[@name=$n]"/>
       
  1561 	<xsl:choose>
       
  1562 		<xsl:when test="not($match)"><xsl:copy-of select="."/></xsl:when>
       
  1563 		<xsl:otherwise>
       
  1564 			<xsl:attribute name="label"><xsl:value-of select="$match/@abbrev"/></xsl:attribute>
       
  1565 			<xsl:copy-of select="$match/@font"/>
       
  1566 			<xsl:if test="not($match/@font)">
       
  1567 				<xsl:copy-of select="$match/ancestor::display-names/@font"/>
       
  1568 			</xsl:if>
       
  1569 		</xsl:otherwise>
       
  1570 	</xsl:choose>
       
  1571 </xsl:template>
       
  1572 
       
  1573 
       
  1574 <xsl:template match="/shapes/colors[@type='highlight' or @type='text-highlight']" mode="styling"><xsl:param name="model"/>
       
  1575 	<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>
       
  1576 	<group type="{@type}" style-id="{$id}">
       
  1577 		<xsl:call-template name="lgd-group-detail"/>
       
  1578 		<xsl:copy-of select="@default"/>
       
  1579 		<xsl:apply-templates select="@label"  mode="legend-abbrev"/>	
       
  1580 		<xsl:apply-templates mode="styling"><xsl:with-param name="id" select="$id"/></xsl:apply-templates>
       
  1581 	</group>
       
  1582 </xsl:template>
       
  1583 
       
  1584 
       
  1585 <xsl:template match="/shapes/borders|/shapes/patterns|/shapes/styles" mode="styling"><xsl:param name="model"/>
       
  1586 	<xsl:variable name="id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>
       
  1587 	<group type="{name(*)}" style-id="{$id}">
       
  1588 		<xsl:call-template name="lgd-group-detail"/>
       
  1589 		<xsl:copy-of select="@default"/>
       
  1590 		<xsl:apply-templates select="@label"  mode="legend-abbrev"/>	
       
  1591 		<xsl:apply-templates mode="styling"><xsl:with-param name="id" select="$id"/></xsl:apply-templates>
       
  1592 	</group>
       
  1593 </xsl:template>
       
  1594 
       
  1595 <xsl:template match="/shapes/colors/color|/shapes/borders/border|/shapes/patterns/overlay|/shapes/styles/style" mode="styling">
       
  1596 	<xsl:variable name="my-id"><xsl:apply-templates select="." mode="style-id"/></xsl:variable>
       
  1597 	<xsl:variable name="el">
       
  1598 		<xsl:choose>
       
  1599 			<xsl:when test="self::color[../@type='highlight' or ../@type='text-highlight']">cmp</xsl:when>
       
  1600 			<xsl:when test="self::color">cbox</xsl:when>
       
  1601 			<xsl:otherwise>cmp</xsl:otherwise>
       
  1602 		</xsl:choose>
       
  1603 	</xsl:variable>
       
  1604 	<xsl:element name="{$el}">
       
  1605 		<xsl:attribute name="style-id"><xsl:value-of select="$my-id"/></xsl:attribute>
       
  1606 		<xsl:apply-templates select="@label"  mode="legend-abbrev"/>
       
  1607 		<xsl:if test="contains(@label,'{')">
       
  1608 			<xsl:attribute name="label-ref"><xsl:value-of select="$my-id"/></xsl:attribute>
       
  1609 		</xsl:if>
       
  1610 		<xsl:if test="@value">
       
  1611 			<xsl:attribute name="lookup"><xsl:value-of select="@value"/></xsl:attribute>
       
  1612 		</xsl:if>
       
  1613 		<xsl:attribute name="value">	
       
  1614 			<xsl:choose>
       
  1615 				<xsl:when test="self::style"><xsl:value-of select="."/></xsl:when>
       
  1616 				<xsl:when test="self::color[not(../@type) or ../@type='background']"><xsl:value-of select="@color"/></xsl:when>
       
  1617 				<xsl:otherwise><xsl:apply-templates select="." mode="ref"/></xsl:otherwise>
       
  1618 			</xsl:choose>
       
  1619 		</xsl:attribute>
       
  1620 	</xsl:element>
       
  1621 </xsl:template>
       
  1622 
       
  1623 <xsl:template match="/techstreams" mode="styling">
       
  1624 	<xsl:param name="id"/>
       
  1625 	<xsl:for-each select="//techstream">
       
  1626 		<cbox value="{@color}" lookup="{@name}" style-id="{$id}-color{count(preceding::techstream)}" detail="component">
       
  1627 			<xsl:variable name="n" select="@name"/>
       
  1628 			<xsl:variable name="match" select="$abbrevs[@name=$n]"/>
       
  1629 			<xsl:if test="$match">
       
  1630 				<xsl:attribute name="label"><xsl:value-of select="$match/@abbrev"/></xsl:attribute>
       
  1631 				<xsl:copy-of select="$match/@font"/>
       
  1632 				<xsl:if test="not($match/@font)">
       
  1633 					<xsl:copy-of select="$match/ancestor::display-names/@font"/>
       
  1634 				</xsl:if>				
       
  1635 			</xsl:if>
       
  1636 		</cbox>
       
  1637 	</xsl:for-each>
       
  1638 </xsl:template>
       
  1639 
       
  1640 <!-- for date formatting: only use if the date functions are *fully* supported (ie not by xalan)
       
  1641 Uses unix date %-encoding, but only a few are supported (see comments)
       
  1642 -->  
       
  1643 <xsl:template name="format-date"><xsl:param name="date" select="."/>
       
  1644 	<xsl:choose>
       
  1645 		<xsl:when test="contains($date,'%')">
       
  1646 			<xsl:value-of select="substring-before($date,'%')"/>
       
  1647 			<xsl:variable name="rest" select="substring-after($date,'%')"/>
       
  1648 			<xsl:choose>
       
  1649 				<xsl:when test="starts-with($rest,'%') or $rest=''">%</xsl:when> <!-- %%     a literal % -->
       
  1650 				<xsl:when test="starts-with($rest,'a')"><xsl:value-of select="date:day-abbreviation()"/></xsl:when> <!--      %a     locale’s abbreviated weekday name (e.g., Sun) -->
       
  1651 				<xsl:when test="starts-with($rest,'A')"><xsl:value-of select="date:day-name()"/></xsl:when> <!--  %A     locale’s full weekday name (e.g., Sunday)-->
       
  1652 				<xsl:when test="starts-with($rest,'b') or starts-with($rest,'h')"><xsl:value-of select="date:month-abbreviation()"/></xsl:when><!--       %b     locale’s abbreviated month name (e.g., Jan)-->
       
  1653 				<xsl:when test="starts-with($rest,'B')"><xsl:value-of select="date:month-name()"/></xsl:when><!--       %B     locale’s full month name (e.g., January)-->
       
  1654 				<xsl:when test="starts-with($rest,'d')"><xsl:number format="01" value="date:day-in-month()"/></xsl:when><!--%d     day of month (e.g, 01)-->
       
  1655 				<xsl:when test="starts-with($rest,'e')"><xsl:number format=" 1" value="date:day-in-month()"/></xsl:when><!--%d     day of month (e.g, 01)-->
       
  1656 				<xsl:when test="starts-with($rest,'F')"><xsl:value-of select="date:date()"/></xsl:when><!--%F     full date; same as %Y-%m-%d-->
       
  1657 				<xsl:when test="starts-with($rest,'H')"><xsl:number format="01" value="date:hour-in-day()"/></xsl:when><!--%H     hour (00..23)-->
       
  1658 				<xsl:when test="starts-with($rest,'I')"><xsl:number format="01" value="((24 + date:hour-in-day() - 1) mod 12) + 1"/></xsl:when><!--%I     hour (01..12)-->
       
  1659 				<xsl:when test="starts-with($rest,'j')"><xsl:number format="001" value="date:day-in-year()"/></xsl:when><!--%j     day of year (001..366)-->
       
  1660 				<xsl:when test="starts-with($rest,'k')"><xsl:number format=" 1" value="date:hour-in-day()"/></xsl:when><!--%k     hour ( 0..23)-->
       
  1661 				<xsl:when test="starts-with($rest,'l')"><xsl:number format=" 1" value="((24 + date:hour-in-day() - 1) mod 12) + 1"/></xsl:when><!--%l     hour ( 1..12)-->
       
  1662 				<xsl:when test="starts-with($rest,'m')"><xsl:number format="01" value="date:month-in-year()"/></xsl:when><!--%m     month (01..12)-->
       
  1663 				<xsl:when test="starts-with($rest,'M')"><xsl:number format="01" value="date:minute-in-hour()"/></xsl:when><!--%M     minute (00..59)-->
       
  1664 				<xsl:when test="starts-with($rest,'p') and date:hour-in-day() &lt; 12">AM</xsl:when><!--%p     locale’s equivalent of either AM or PM; blank if not known-->
       
  1665 				<xsl:when test="starts-with($rest,'p')">PM</xsl:when><!--%p     locale’s equivalent of either AM or PM; blank if not known-->
       
  1666 				<xsl:when test="starts-with($rest,'P') and date:hour-in-day() &lt; 12">am</xsl:when><!--%P     like %p, but lower case-->
       
  1667 				<xsl:when test="starts-with($rest,'P')">pm</xsl:when><!--%P     like %p, but lower case-->
       
  1668 				<xsl:when test="starts-with($rest,'S')"><xsl:number format="01" value="date:second-in-minute()"/></xsl:when><!--%S     second (00..60)-->
       
  1669 				<xsl:when test="starts-with($rest,'T')"><xsl:value-of select="date:time()"/></xsl:when><!--%T     time; same as %H:%M:%S-->
       
  1670 				<xsl:when test="starts-with($rest,'u')"><xsl:value-of select="((date:day-in-week() +5) mod 7) + 1"/></xsl:when><!--%u     day of week (1..7); 1 is Monday-->
       
  1671 				<xsl:when test="starts-with($rest,'V')"><xsl:value-of select="date:week-in-year()"/></xsl:when><!--%V     ISO week number, with Monday as first day of week (01..53)-->
       
  1672 				<xsl:when test="starts-with($rest,'w')"><xsl:value-of select="date:day-in-week() - 1"/></xsl:when><!--%w     day of week (0..6); 0 is Sunday-->
       
  1673 				<xsl:when test="starts-with($rest,'y')"><xsl:value-of select="date:year() mod 100"/></xsl:when><!--%y     last two digits of year (00..99)-->
       
  1674 				<xsl:when test="starts-with($rest,'Y')"><xsl:value-of select="date:year()"/></xsl:when><!--%Y     year-->
       
  1675 				<xsl:otherwise><xsl:value-of select="substring($rest,1,1)"/></xsl:otherwise>
       
  1676 			</xsl:choose>
       
  1677 			<xsl:if test="string-length($rest) &gt; 1">
       
  1678 				<xsl:call-template name="format-date">
       
  1679 					<xsl:with-param name="date" select="substring($rest,2)"/>
       
  1680 				</xsl:call-template>
       
  1681 			</xsl:if>
       
  1682 		</xsl:when>
       
  1683 		<xsl:otherwise><xsl:value-of select="$date"/></xsl:otherwise>
       
  1684 	</xsl:choose>
       
  1685 </xsl:template>
       
  1686 
       
  1687 <xsl:include href="draw.xsl"/>
       
  1688 </xsl:stylesheet>