bldsystemtools/sysdeftools/filtering.xsl
changeset 0 83f4b4db085c
child 2 99082257a271
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 <?xml version="1.0"?>
       
     2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common"  exclude-result-prefixes="exslt">
       
     3 <!--Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 	All rights reserved.
       
     5 	This component and the accompanying materials are made available
       
     6 	under the terms of the License "Eclipse Public License v1.0"
       
     7 	which accompanies this distribution, and is available
       
     8 	at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 
       
    10 	Initial Contributors:
       
    11 	Nokia Corporation - initial contribution.
       
    12 	Contributors:
       
    13 	Description:
       
    14 	Filter a sysdef in the 2.0 or 3.0 syntax
       
    15 -->
       
    16 <xsl:output method="xml" indent="yes"/>
       
    17 
       
    18 <xsl:param name="filter-type">only</xsl:param> <!-- only, has or with -->
       
    19 
       
    20 <xsl:param name="filter"/> <!-- comma-separated list -->
       
    21 
       
    22 <xsl:param name="addbuild" select="0"/> <!-- add a system build section that accepts everything -->
       
    23 
       
    24 
       
    25 <xsl:template match="node()|@*"><xsl:copy-of select="."/></xsl:template>
       
    26 <xsl:template match="*"><xsl:param name="data"/>
       
    27 	<xsl:copy>
       
    28 		<xsl:copy-of select="@*"/>
       
    29 		<xsl:apply-templates select="node()">
       
    30 			<xsl:with-param name="data" select="$data"/>
       
    31 		</xsl:apply-templates>
       
    32 	</xsl:copy>
       
    33 </xsl:template>
       
    34 
       
    35 <xsl:template match="component|unit"><xsl:param name="data"/> <!-- filterable items -->
       
    36 	 <xsl:variable name="display">
       
    37 	 	<xsl:apply-templates select="$data" mode="filter">
       
    38 			<xsl:with-param name="item" select="current()"/>
       
    39 		</xsl:apply-templates>
       
    40 	 </xsl:variable>
       
    41 	 
       
    42 	 <xsl:if test="$display != 'hide' "> <!-- if hide, remove completely from the output-->
       
    43 		<xsl:copy>
       
    44 			<xsl:copy-of select="@*"/>
       
    45 			<xsl:apply-templates select="node()">
       
    46 				<xsl:with-param name="data" select="$data"/>
       
    47 			</xsl:apply-templates>
       
    48 		</xsl:copy>
       
    49 	</xsl:if>
       
    50 </xsl:template>
       
    51 
       
    52 <xsl:template match="/SystemDefinition">
       
    53 	<xsl:variable name="f">
       
    54 		<xsl:element name="filter-{$filter-type}">
       
    55 			<xsl:call-template name="filter-list">
       
    56 				<xsl:with-param name="f" select="$filter"/>
       
    57 			</xsl:call-template>
       
    58 		</xsl:element>
       
    59 	</xsl:variable>
       
    60 	<xsl:choose>
       
    61 		<xsl:when test="starts-with(@schema,'3.0')"/> <!-- no DTD needed for 3.0 sysdef -->
       
    62 		<xsl:when test="$addbuild">
       
    63 			<xsl:call-template name="DTD-bld"/> <!-- insert 2.0.1 DTD w/sysbuild parts-->
       
    64 		</xsl:when>
       
    65 		<xsl:otherwise>
       
    66 			<xsl:call-template name="DTD"/> <!-- insert 2.0.1 DTD -->
       
    67 		</xsl:otherwise>
       
    68 	</xsl:choose>
       
    69 	<xsl:copy>
       
    70 		<xsl:copy-of select="@*"/>
       
    71 		<xsl:variable name="content"> <!-- save content for potential further processing -->
       
    72 			<xsl:apply-templates select="node()">
       
    73 				<xsl:with-param name="data" select="exslt:node-set($f)/*"/>
       
    74 			</xsl:apply-templates>
       
    75 		</xsl:variable>
       
    76 		<!-- just output content as is. We could create a template to remove any filtered out items, but so far there's no compelling need -->
       
    77 		<xsl:copy-of select="$content"/>  
       
    78 
       
    79 		<xsl:if test="$addbuild">
       
    80 			<SystemBuild schema="1.0.0">
       
    81 				<configuration name="any" description="text">
       
    82 					<xsl:attribute name="filter">
       
    83 						<xsl:for-each select="//@filter[not(.=following::*/@filter)]">
       
    84 							<xsl:value-of select="."/><xsl:if test="position()!=last()">,</xsl:if>
       
    85 						</xsl:for-each>
       
    86 					</xsl:attribute>
       
    87 					<xsl:for-each select="exslt:node-set($content)/systemModel/layer[descendant::unit]">
       
    88 						<!-- only include layers we know have units -->
       
    89 						<ref item="{@name}"/>
       
    90 					</xsl:for-each>
       
    91 				</configuration>
       
    92 			</SystemBuild>
       
    93 		</xsl:if>
       
    94 	</xsl:copy>
       
    95 </xsl:template>
       
    96 
       
    97 
       
    98 <xsl:include href="filter-module.xsl"/>
       
    99 
       
   100 <xsl:template name="DTD-bld">
       
   101 <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE SystemDefinition [
       
   102  <!ELEMENT SystemDefinition ( systemModel?, SystemBuild? )>
       
   103  <!ATTLIST SystemDefinition
       
   104   name CDATA #REQUIRED
       
   105   schema CDATA #REQUIRED>
       
   106  <!ELEMENT systemModel (layer+)>
       
   107  <!ELEMENT layer (block* | collection*)*>
       
   108  <!ATTLIST layer
       
   109   name CDATA #REQUIRED
       
   110   long-name CDATA #IMPLIED
       
   111   levels NMTOKENS #IMPLIED
       
   112   span CDATA #IMPLIED>
       
   113  <!ELEMENT block (subblock* | collection*)*>
       
   114  <!ATTLIST block
       
   115   levels NMTOKENS #IMPLIED
       
   116   span CDATA #IMPLIED
       
   117   level NMTOKEN #IMPLIED
       
   118   name CDATA #REQUIRED
       
   119   long-name CDATA #IMPLIED>
       
   120  <!ELEMENT subblock (collection)*>
       
   121  <!ATTLIST subblock
       
   122   name CDATA #REQUIRED
       
   123   long-name CDATA #IMPLIED>
       
   124  <!ELEMENT collection (component)*>
       
   125  <!ATTLIST collection
       
   126   name CDATA #REQUIRED
       
   127   long-name CDATA #IMPLIED
       
   128   level NMTOKEN #IMPLIED>
       
   129  <!ELEMENT component (unit)*>
       
   130  <!ATTLIST component
       
   131   name CDATA #REQUIRED
       
   132   long-name CDATA #IMPLIED
       
   133   deprecated CDATA #IMPLIED
       
   134   introduced CDATA #IMPLIED
       
   135   contract CDATA #IMPLIED
       
   136   plugin (Y|N) "N"
       
   137   filter CDATA #IMPLIED
       
   138   class NMTOKENS #IMPLIED
       
   139   supports CDATA #IMPLIED
       
   140   purpose ( optional | mandatory | development ) "optional">
       
   141  <!ELEMENT unit EMPTY>
       
   142  <!ATTLIST unit
       
   143   mrp CDATA #IMPLIED
       
   144   filter CDATA #IMPLIED
       
   145   bldFile CDATA #IMPLIED
       
   146   root CDATA #IMPLIED
       
   147   version NMTOKEN #IMPLIED
       
   148   prebuilt NMTOKEN #IMPLIED
       
   149   late (Y|N) #IMPLIED
       
   150   priority CDATA #IMPLIED>
       
   151  <!ELEMENT SystemBuild (option* | target+ | targetList+ | list+ | configuration+)*>
       
   152  <!ATTLIST SystemBuild schema CDATA #REQUIRED>
       
   153  <!ELEMENT list (ref+)>
       
   154  <!ATTLIST list
       
   155   name ID #REQUIRED
       
   156   description CDATA #REQUIRED>
       
   157  <!ELEMENT ref EMPTY>
       
   158  <!ATTLIST ref item CDATA #REQUIRED>
       
   159  <!ELEMENT targetList EMPTY>
       
   160  <!ATTLIST targetList
       
   161   name ID #REQUIRED
       
   162   description CDATA #REQUIRED
       
   163   target IDREFS #REQUIRED>
       
   164  <!ELEMENT target EMPTY>
       
   165  <!ATTLIST target
       
   166   name ID #REQUIRED
       
   167   abldTarget CDATA #REQUIRED
       
   168   description CDATA #REQUIRED>
       
   169  <!ELEMENT option EMPTY>
       
   170  <!ATTLIST option
       
   171   name ID #REQUIRED
       
   172   abldOption CDATA #REQUIRED
       
   173   description CDATA #REQUIRED
       
   174   enable (Y | N ) #REQUIRED>
       
   175  <!ELEMENT configuration (listRef+ | ref+ | task+)*>
       
   176  <!ATTLIST configuration
       
   177   name ID #REQUIRED
       
   178   description CDATA #REQUIRED
       
   179   filter CDATA #REQUIRED>
       
   180  <!ELEMENT task (listRef* , (buildLayer | specialInstructions))>
       
   181  <!ELEMENT listRef EMPTY>
       
   182  <!ATTLIST listRef list CDATA #REQUIRED>
       
   183  <!ELEMENT buildLayer EMPTY>
       
   184  <!ATTLIST buildLayer
       
   185   command CDATA #REQUIRED
       
   186   targetList IDREFS #IMPLIED
       
   187   unitParallel (Y | N ) #REQUIRED
       
   188   targetParallel (Y | N ) "N">
       
   189  <!ELEMENT specialInstructions EMPTY>
       
   190  <!ATTLIST specialInstructions
       
   191   name CDATA #REQUIRED
       
   192   cwd CDATA #REQUIRED
       
   193   root CDATA #IMPLIED
       
   194   command CDATA #REQUIRED>
       
   195 ]>
       
   196 ]]></xsl:text>
       
   197 </xsl:template>
       
   198 
       
   199 <xsl:template name="DTD">
       
   200 <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE SystemDefinition [
       
   201 <!ELEMENT SystemDefinition ( systemModel )>
       
   202 <!ATTLIST SystemDefinition
       
   203   name CDATA #REQUIRED
       
   204   schema CDATA #REQUIRED
       
   205 >
       
   206 <!-- all paths are relative to the environment variable specified by the root attribute, or SOURCEROOT if not.  -->
       
   207 
       
   208 <!-- System Model Section of DTD -->
       
   209 <!ELEMENT systemModel (layer+)>
       
   210 
       
   211 <!ELEMENT layer (block* | collection*)*>
       
   212 <!-- Kernel Services, Base Services, OS Services, Etc -->
       
   213 <!ATTLIST layer
       
   214   name CDATA #REQUIRED
       
   215   long-name CDATA #IMPLIED
       
   216   levels NMTOKENS #IMPLIED
       
   217   span CDATA #IMPLIED
       
   218 >
       
   219 
       
   220 <!ELEMENT block (subblock* | collection*)*>
       
   221  <!-- Generic OS services, Comms Services, etc -->
       
   222 <!ATTLIST block
       
   223   levels NMTOKENS #IMPLIED
       
   224   span CDATA #IMPLIED
       
   225   level NMTOKEN #IMPLIED
       
   226   name CDATA #REQUIRED
       
   227   long-name CDATA #IMPLIED
       
   228 >
       
   229 
       
   230 <!ELEMENT subblock (collection)*>
       
   231 <!-- Cellular Baseband Services, Networking Services, etc -->
       
   232 <!ATTLIST subblock
       
   233   name CDATA #REQUIRED
       
   234   long-name CDATA #IMPLIED
       
   235 >
       
   236 
       
   237 <!ELEMENT collection (component)*>
       
   238 <!-- Screen Driver, Content Handling, etc -->
       
   239 <!ATTLIST collection
       
   240   name CDATA #REQUIRED
       
   241   long-name CDATA #IMPLIED
       
   242   level NMTOKEN #IMPLIED
       
   243 >
       
   244 
       
   245 <!ELEMENT component (unit)*>
       
   246 <!-- contains units or is a  package or prebuilt -->
       
   247 <!ATTLIST component
       
   248   name CDATA #REQUIRED
       
   249   long-name CDATA #IMPLIED
       
   250   deprecated CDATA #IMPLIED
       
   251   introduced CDATA #IMPLIED
       
   252   contract CDATA #IMPLIED
       
   253   plugin (Y|N) "N"
       
   254   filter CDATA #IMPLIED
       
   255   class NMTOKENS #IMPLIED
       
   256   supports CDATA #IMPLIED
       
   257   purpose ( optional | mandatory | development ) "optional"
       
   258 >
       
   259 
       
   260 <!ELEMENT unit EMPTY >
       
   261 <!-- must be buildable (bld.inf) -->
       
   262 <!-- bldFile  may someday be removed in favour of mrp -->
       
   263 <!ATTLIST unit
       
   264   mrp CDATA #IMPLIED
       
   265   filter CDATA #IMPLIED
       
   266   bldFile CDATA #IMPLIED
       
   267   root CDATA #IMPLIED
       
   268   version NMTOKEN #IMPLIED
       
   269   prebuilt NMTOKEN #IMPLIED
       
   270   late (Y|N) #IMPLIED
       
   271   priority CDATA #IMPLIED
       
   272 >
       
   273 ]>
       
   274 ]]></xsl:text>
       
   275 </xsl:template>
       
   276 </xsl:stylesheet>