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