sysmodellibs/sysmodelgen/extra/validate-raw.xsl
changeset 7 3c36c452f013
parent 6 5b32dc297d05
equal deleted inserted replaced
6:5b32dc297d05 7:3c36c452f013
       
     1 <stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform" 	xmlns:set="http://exslt.org/sets">
       
     2 <output method="text"/>
       
     3 <key name="name" match="component|collection|package|layer" use="@id"/>
       
     4 
       
     5 <template match="/*" priority="-1">
       
     6 ERROR: Invalid root element: <value-of select="name()"/>
       
     7 </template>
       
     8 
       
     9 <template match="*" priority="-5">
       
    10 ERROR: Invalid element: <value-of select="name()"/>
       
    11 </template>
       
    12 
       
    13 
       
    14 
       
    15 <template match="component/Build"/> <!-- for depmodel -->
       
    16 
       
    17 <template match="@*" priority="-5">
       
    18 NOTE: unexpected attribute "<value-of select="name()"/>" on &lt;<value-of select="name(..)"/>&gt;</template>
       
    19 
       
    20 
       
    21 <template match="text()">
       
    22 <if test="normalize-space(.)!=''">
       
    23 ERROR: unexepected text: <value-of select="."/></if>
       
    24 </template>
       
    25 
       
    26 
       
    27 <template match="/SystemDefinition">
       
    28 <if test="not(systemModel/@name)">
       
    29 Note: missing System Model name</if>
       
    30 <for-each select="systemModel//*[@id]">
       
    31 	<if test="count(key('name',@id)) &gt; 1">
       
    32 ERROR: duplicate name for <value-of select="name()"/> "<value-of select="@id"/>" (<value-of select="count(key('name',@id))"/>)	<apply-templates mode="location" select=".."/></if>
       
    33 </for-each>
       
    34 <apply-templates select="@schema | node()"/>
       
    35 <call-template name="extra-atts"/>
       
    36 <call-template name="extra-atts"><with-param name="item">collection</with-param></call-template>
       
    37 <call-template name="extra-atts"><with-param name="item">package</with-param></call-template>
       
    38 <call-template name="extra-atts"><with-param name="item">layer</with-param></call-template>
       
    39 <variable name="levels">
       
    40 	<for-each select="set:distinct(//@level)">
       
    41 	   <value-of select="concat(.,' ')"/>
       
    42    </for-each>
       
    43   </variable>
       
    44 <if test="$levels!=''">
       
    45 Note: Level names used: <value-of select="normalize-space($levels)"/></if>
       
    46 </template>
       
    47 
       
    48 <template name="extra-atts"><param name="item">component</param>
       
    49 <variable name="atts">
       
    50 	<for-each select="//*[name()=$item]/@*"><variable name="n" select="name()"/>
       
    51 	<if test="not(following::*[name()=$item]/@*[name()=$n])">
       
    52 	   <apply-templates mode="extra" select="."/></if>
       
    53 	</for-each>
       
    54 </variable>
       
    55 <if test="$atts!=''">
       
    56 Note: Extra <value-of select="$item"/> attributes: <value-of select="normalize-space($atts)"/></if>
       
    57 </template>
       
    58 
       
    59 <template match="@*" mode="extra">
       
    60 	   <value-of select="concat(name(), ' ')"/>
       
    61 </template>
       
    62 
       
    63 
       
    64 <template match="collection/@level | package/@level | package/@span | layer/@span| layer/@levels | package/@levels | @name | @id | @before |component/@filter |component/@contract |component/@deprecated |component/@class |component/@introduced |component/@purpose|component/@target" mode="extra"/>
       
    65 
       
    66 
       
    67 <template match="/SystemDefinition/@schema">
       
    68 <choose>
       
    69 	<when test="starts-with(.,'3.')"/>
       
    70 <otherwise>
       
    71 ERROR: unsupported syntax: <value-of select="."/></otherwise>
       
    72 </choose>
       
    73 </template>
       
    74 
       
    75 
       
    76 
       
    77 <template match="@level">
       
    78 WARNING: invalid attribute "<value-of select="name()"/>" on &lt;<value-of select="name(..)"/>&gt;</template>
       
    79 	
       
    80 <template match="systemModel/layer|layer/package|package/package| package/collection| collection/component |
       
    81 	SystemDefinition/layer| SystemDefinition/package| SystemDefinition/collection| SystemDefinition/component">
       
    82 	<apply-templates select="@*|node()"/>
       
    83 </template>
       
    84 
       
    85 
       
    86 <template match="layer|package|collection|component" priority="-3">
       
    87 ERROR: &lt;<value-of select="name()"/> name="<value-of select="@id"/>"&gt; cannot be a child of &lt;<value-of select="name(..)"/>&gt;</template>
       
    88 
       
    89 
       
    90 
       
    91 <template match="package/@level">
       
    92 <if test="not(contains(concat(' ',normalize-space(../../@levels), ' '),concat(' ',normalize-space(.), ' ')))">
       
    93 ERROR: Invalid level name "<value-of select="."/>" on <value-of select="name(..)"/> "<value-of select="../@id"/>" (<value-of select="../../@levels"/>)</if>
       
    94 </template>
       
    95 
       
    96 <template match="collection/@level">
       
    97 <choose>
       
    98 	<when test="ancestor::package/@levels">
       
    99 		<if test="not(contains(concat(' ',normalize-space(ancestor::package/@levels), ' '),concat(' ',normalize-space(.), ' ')))">
       
   100 ERROR: Invalid level name "<value-of select="."/>" on <value-of select="name(..)"/> "<value-of select="../@id"/>" (<value-of select="../../@levels"/>)</if>
       
   101 	</when>
       
   102 	<otherwise>
       
   103 		<if test="not(contains(concat(' ',normalize-space(ancestor::layer/@levels), ' '),concat(' ',normalize-space(.), ' ')))">
       
   104 ERROR: Invalid level name "<value-of select="."/>" on <value-of select="name(..)"/> "<value-of select="../@id"/>" (<value-of select="../../@levels"/>)</if>
       
   105 	</otherwise>
       
   106 </choose>
       
   107 </template>
       
   108 
       
   109 
       
   110 
       
   111 <template match="component/@plugin">
       
   112 	<if test=".!='Y' and .!='N'">
       
   113 WARNING: invalid <value-of select="name()"/> value "<value-of select="."/>" on &lt;<value-of select="name(..)"/> name="<value-of select="../@id"/>"&gt;</if>
       
   114 </template>
       
   115 
       
   116 
       
   117 <template match="logicalset|logicalsubset|module|SystemBuild">
       
   118 ERROR: using 1.x syntax element: &lt;<value-of select="name()"/>&gt;</template>
       
   119 
       
   120 <template match="unit/@name | unit/@unitID">
       
   121 <if test="not(starts-with(/SystemDefinition/@schema,'1.'))">
       
   122 WARNING: using 1.x syntax attribute: &lt;<value-of select="concat(name(..),' ',name())"/>="<value-of select="."/>"&gt;</if>
       
   123 </template>
       
   124 
       
   125 <template match="@name | layer/@levels |package/@levels | component/@class | component/@filter | component/@introduced  | component/@deprecated | component/@contract"> <!-- validate elsewhere -->
       
   126 	<if test=".=''">
       
   127 ERROR: attribute "<value-of select="name()"/>" on &lt;<value-of select="name(..)"/>&gt; must not be empty</if>
       
   128 </template>
       
   129 
       
   130 <template match="systemModel|meta">
       
   131 	<apply-templates select="@*|node()"/>
       
   132 </template>
       
   133 
       
   134 <template match="meta/*"/> <!-- anything's valid-->
       
   135 
       
   136 <template match="meta/@href | meta/@rel | meta/@type"/>
       
   137 
       
   138 <template match="unit[starts-with(/SystemDefinition/@schema,'1.')]/@contract"/>
       
   139 
       
   140 
       
   141 <template match="unit/@mrp | unit/@bldFile">
       
   142 <choose>
       
   143 <when test="starts-with(/SystemDefinition/@schema,'1.')">
       
   144 	<if test="contains(.,'/')">
       
   145 WARINING: path separator must be "\" for <value-of select="name()"/>="<value-of select="."/>"</if>
       
   146 </when>
       
   147 <otherwise>
       
   148 	<if test="contains(.,'\')">
       
   149 WARINING: path separator must be "/" for <value-of select="name()"/>="<value-of select="."/>"</if>
       
   150 </otherwise>
       
   151 </choose>
       
   152 </template>
       
   153 
       
   154 
       
   155 <template match="unit/@version | unit/@priority | unit/@filter | unit/@root"/> <!-- handle later-->
       
   156 <template match="package/@* | prebuilt/@*"/> <!-- handle later-->
       
   157 
       
   158 <template match="unit|component/package|prebuilt">
       
   159 	<if test="*">
       
   160 WARNING: &lt;<value-of select="name()"/>&gt; must be empty.</if>
       
   161 
       
   162 <if test="not(starts-with(/SystemDefinition/@schema,'1.'))">
       
   163 <if test="count(../unit | ../package | ../prebuilt) != 1 and count(../*[@filter or @version]) != count(../*)">
       
   164 WARNING: multiple units must have "version" or "filter" attributes (<value-of select="../@id"/>)</if>
       
   165 <if test="self::prebuilt or self::package">
       
   166 ERROR: using 1.x syntax element: &lt;<value-of select="name()"/>&gt;</if>
       
   167 </if>
       
   168 <apply-templates select="@*"/>
       
   169 </template>
       
   170 
       
   171 <template mode="location" match="*">
       
   172 <for-each select="ancestor::*[(self::layer or self::package or self::collection) and @name]">[<value-of select="substring(name(),1,1)"/>] <value-of select="@id"/>
       
   173 	<if test="position()=1"> / </if>
       
   174 </for-each>
       
   175 </template>
       
   176 </stylesheet>