plcopen/instance_tagname.xslt
changeset 1321 83f41ea00b97
child 1326 e2c11668addf
equal deleted inserted replaced
1320:bb04c41cbee9 1321:83f41ea00b97
       
     1 <xsl:stylesheet version="1.0"
       
     2     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       
     3     xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
       
     4     xmlns:xhtml="http://www.w3.org/1999/xhtml"
       
     5     xmlns:ns="instance_tagname_ns"
       
     6     extension-element-prefixes="ns"
       
     7     exclude-result-prefixes="ns">
       
     8   <xsl:param name="instance_path"/>
       
     9   <xsl:template name="element_name">
       
    10     <xsl:param name="path"/>
       
    11     <xsl:choose>
       
    12       <xsl:when test="contains($path,'.')">
       
    13         <xsl:value-of select="substring-before($path,'.')"/>
       
    14       </xsl:when>
       
    15       <xsl:otherwise>
       
    16         <xsl:value-of select="$path"/>
       
    17       </xsl:otherwise>
       
    18     </xsl:choose>
       
    19   </xsl:template>
       
    20   <xsl:template name="next_path">
       
    21     <xsl:param name="path"/>
       
    22     <xsl:choose>
       
    23       <xsl:when test="contains($path,'.')">
       
    24         <xsl:value-of select="substring-after($path,'.')"/>
       
    25       </xsl:when>
       
    26     </xsl:choose>
       
    27   </xsl:template>
       
    28   <xsl:template match="ppx:project">
       
    29     <xsl:variable name="config_name">
       
    30       <xsl:call-template name="element_name">
       
    31         <xsl:with-param name="path" select="$instance_path"/>
       
    32       </xsl:call-template>
       
    33     </xsl:variable>
       
    34     <xsl:apply-templates select="ppx:instances/ppx:configurations/ppx:configuration[@name=$config_name]">
       
    35       <xsl:with-param name="element_path">
       
    36         <xsl:call-template name="next_path">
       
    37           <xsl:with-param name="path" select="$instance_path"/>
       
    38         </xsl:call-template>
       
    39       </xsl:with-param>
       
    40     </xsl:apply-templates>
       
    41   </xsl:template>
       
    42   <xsl:template match="ppx:configuration">
       
    43     <xsl:param name="element_path"/>
       
    44     <xsl:choose>
       
    45       <xsl:when test="$element_path!=''">
       
    46         <xsl:variable name="child_name">
       
    47 	      <xsl:call-template name="element_name">
       
    48 	        <xsl:with-param name="path" select="$element_path"/>
       
    49 	      </xsl:call-template>
       
    50 	    </xsl:variable>
       
    51         <xsl:apply-templates select="ppx:resource[@name=$child_name] | ppx:globalVars/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
    52           <xsl:with-param name="element_path">
       
    53             <xsl:call-template name="next_path">
       
    54 		      <xsl:with-param name="path" select="$element_path"/>
       
    55 		    </xsl:call-template>
       
    56 		  </xsl:with-param>
       
    57         </xsl:apply-templates>
       
    58       </xsl:when>
       
    59       <xsl:otherwise>
       
    60         <ns:config_tagname>
       
    61           <xsl:attribute name="name">
       
    62             <xsl:value-of select="@name"/>
       
    63           </xsl:attribute>
       
    64         </ns:config_tagname>
       
    65       </xsl:otherwise>
       
    66     </xsl:choose>
       
    67   </xsl:template>
       
    68   <xsl:template match="ppx:resource">
       
    69     <xsl:param name="element_path"/>
       
    70     <xsl:choose>
       
    71       <xsl:when test="$element_path!=''">
       
    72 	    <xsl:variable name="child_name">
       
    73 	      <xsl:call-template name="element_name">
       
    74 	        <xsl:with-param name="path" select="$element_path"/>
       
    75 	      </xsl:call-template>
       
    76 	    </xsl:variable>
       
    77         <xsl:apply-templates select="ppx:pouInstance[@name=$child_name] | ppx:task|ppx:pouInstance[@name=$child_name] | ppx:globalVars/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
    78           <xsl:with-param name="element_path">
       
    79             <xsl:call-template name="next_path">
       
    80               <xsl:with-param name="path" select="$element_path"/>
       
    81             </xsl:call-template>
       
    82           </xsl:with-param>
       
    83         </xsl:apply-templates>
       
    84       </xsl:when>
       
    85       <xsl:otherwise>
       
    86         <ns:resource_tagname>
       
    87           <xsl:attribute name="name">
       
    88             <xsl:value-of select="@name"/>
       
    89           </xsl:attribute>
       
    90           <xsl:attribute name="config_name">
       
    91             <xsl:value-of select="ancestor::ppx:configuration/@name"/>
       
    92           </xsl:attribute>
       
    93         </ns:resource_tagname>
       
    94       </xsl:otherwise>
       
    95     </xsl:choose>
       
    96   </xsl:template>
       
    97   <xsl:template match="ppx:pouInstance">
       
    98     <xsl:param name="element_path"/>
       
    99     <ns:instance_definition>
       
   100       <xsl:attribute name="name">
       
   101         <xsl:value-of select="@typeName"/>
       
   102       </xsl:attribute>
       
   103       <xsl:attribute name="path">
       
   104         <xsl:value-of select="$element_path"/>
       
   105       </xsl:attribute>
       
   106     </ns:instance_definition>
       
   107   </xsl:template>
       
   108   <xsl:template match="ppx:pou">
       
   109     <xsl:param name="element_path"/>
       
   110     <xsl:variable name="child_name">
       
   111       <xsl:call-template name="element_name">
       
   112         <xsl:with-param name="path" select="$element_path"/>
       
   113       </xsl:call-template>
       
   114     </xsl:variable>
       
   115     <xsl:variable name="next_child_path">
       
   116       <xsl:call-template name="next_path">
       
   117         <xsl:with-param name="path" select="$element_path"/>
       
   118       </xsl:call-template>
       
   119     </xsl:variable>
       
   120     <xsl:apply-templates select="ppx:interface/*/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
   121       <xsl:with-param name="next_child_path" select="next_child_path"/>
       
   122     </xsl:apply-templates>
       
   123     <xsl:apply-templates select="ppx:actions/ppx:action[@name=$child_name]">
       
   124       <xsl:with-param name="next_child_path" select="next_child_path"/>
       
   125     </xsl:apply-templates>
       
   126     <xsl:apply-templates select="ppx:transitions/ppx:transition[@name=$child_name]">
       
   127       <xsl:with-param name="next_child_path" select="next_child_path"/>
       
   128     </xsl:apply-templates>
       
   129   </xsl:template>
       
   130   <xsl:template match="ppx:action">
       
   131     <ns:action_tagname>
       
   132       <xsl:attribute name="name">
       
   133         <xsl:value-of select="@name"/>
       
   134       </xsl:attribute>
       
   135       <xsl:attribute name="pou_name">
       
   136         <xsl:value-of select="ancestor::ppx:pou/@name"/>
       
   137       </xsl:attribute>
       
   138     </ns:action_tagname>
       
   139   </xsl:template>
       
   140   <xsl:template match="ppx:transition">
       
   141     <ns:transition_tagname>
       
   142       <xsl:attribute name="name">
       
   143         <xsl:value-of select="@name"/>
       
   144       </xsl:attribute>
       
   145       <xsl:attribute name="pou_name">
       
   146         <xsl:value-of select="ancestor::ppx:pou/@name"/>
       
   147       </xsl:attribute>
       
   148     </ns:transition_tagname>
       
   149   </xsl:template>
       
   150   <xsl:template name="ppx:dataType">
       
   151     <xsl:param name="element_path"/>
       
   152     <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
   153       <xsl:with-param name="element_path" select="element_path"/>
       
   154     </xsl:apply-templates>
       
   155   </xsl:template>
       
   156   <xsl:template match="ppx:derived">
       
   157     <xsl:param name="element_path"/>
       
   158     <ns:instance_definition>
       
   159       <xsl:attribute name="name">
       
   160         <xsl:value-of select="@name"/>
       
   161       </xsl:attribute>
       
   162       <xsl:attribute name="path">
       
   163         <xsl:value-of select="$element_path"/>
       
   164       </xsl:attribute>
       
   165     </ns:instance_definition>
       
   166   </xsl:template>
       
   167   <xsl:template match="array">
       
   168     <xsl:param name="element_path"/>
       
   169     <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
   170       <xsl:with-param name="element_path" select="element_path"/>
       
   171     </xsl:apply-templates>
       
   172   </xsl:template>
       
   173   <xsl:template match="struct">
       
   174     <xsl:param name="element_path"/>
       
   175     <xsl:variable name="child_name">
       
   176       <xsl:call-template name="element_name">
       
   177         <xsl:with-param name="path" select="$element_path"/>
       
   178       </xsl:call-template>
       
   179     </xsl:variable>
       
   180     <xsl:variable name="next_child_path">
       
   181       <xsl:call-template name="next_path">
       
   182         <xsl:with-param name="path" select="$element_path"/>
       
   183       </xsl:call-template>
       
   184     </xsl:variable>
       
   185     <xsl:apply-templates select="ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
   186       <xsl:with-param name="element_path" select="element_path"/>
       
   187     </xsl:apply-templates>
       
   188   </xsl:template>
       
   189   <xsl:template match="pou_instance">
       
   190     <xsl:choose>
       
   191       <xsl:when test="@pou_path!=''">
       
   192         <xsl:apply-templates>
       
   193           <xsl:with-param name="element_path" select="@pou_path"/>
       
   194         </xsl:apply-templates>        
       
   195       </xsl:when>
       
   196       <xsl:otherwise>
       
   197         <ns:pou_tagname>
       
   198           <xsl:attribute name="name">
       
   199             <xsl:value-of select="ppx:pou/@name"/>
       
   200           </xsl:attribute>
       
   201         </ns:pou_tagname>
       
   202       </xsl:otherwise>
       
   203     </xsl:choose>
       
   204   </xsl:template>
       
   205   <xsl:template match="datatype_instance">
       
   206     <xsl:apply-templates>
       
   207       <xsl:with-param name="element_path" select="@datatype_path"/>
       
   208     </xsl:apply-templates>
       
   209   </xsl:template>
       
   210 </xsl:stylesheet>