plcopen/instances_path.xslt
changeset 1350 7280349a3375
parent 1319 748347102c97
child 1352 9ec4ac8e2955
equal deleted inserted replaced
1349:be6c3a036844 1350:7280349a3375
     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="instances_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:ns="instances_ns"
     4   <xsl:variable name="space" select="'                                                                                                                                                                                                        '"/>
     5     extension-element-prefixes="ns"
     5   <xsl:param name="autoindent" select="4"/>
     6     exclude-result-prefixes="ns">
       
     7   <xsl:param name="instance_type"/>
     6   <xsl:param name="instance_type"/>
       
     7   <xsl:template match="text()">
       
     8     <xsl:param name="_indent" select="0"/>
       
     9   </xsl:template>
       
    10   <xsl:variable name="project">
       
    11     <xsl:copy-of select="document('project')/project/*"/>
       
    12   </xsl:variable>
       
    13   <xsl:variable name="stdlib">
       
    14     <xsl:copy-of select="document('stdlib')/stdlib/*"/>
       
    15   </xsl:variable>
       
    16   <xsl:variable name="extensions">
       
    17     <xsl:copy-of select="document('extensions')/extensions/*"/>
       
    18   </xsl:variable>
     8   <xsl:template match="ppx:project">
    19   <xsl:template match="ppx:project">
     9    <instances>
    20     <xsl:param name="_indent" select="0"/>
    10      <xsl:apply-templates select="ppx:instances/ppx:configurations/ppx:configuration"/>
    21     <instances>
    11    </instances>
    22       <xsl:apply-templates select="ppx:instances/ppx:configurations/ppx:configuration">
       
    23         <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
    24       </xsl:apply-templates>
       
    25     </instances>
    12   </xsl:template>
    26   </xsl:template>
    13   <xsl:template match="ppx:configuration">
    27   <xsl:template match="ppx:configuration">
    14     <xsl:apply-templates select="ppx:globalVars/ppx:variable[ppx:type/ppx:derived]">
    28     <xsl:param name="_indent" select="0"/>
    15       <xsl:with-param name="parent_path" select="@name"/>
    29     <xsl:apply-templates select="ppx:globalVars/ppx:variable[ppx:type/ppx:derived] | ppx:resource">
    16     </xsl:apply-templates>
    30       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
    17     <xsl:apply-templates select="ppx:resource">
    31       <xsl:with-param name="parent_path">
    18       <xsl:with-param name="parent_path" select="@name"/>
    32         <xsl:value-of select="@name"/>
       
    33       </xsl:with-param>
    19     </xsl:apply-templates>
    34     </xsl:apply-templates>
    20   </xsl:template>
    35   </xsl:template>
    21   <xsl:template match="ppx:resource">
    36   <xsl:template match="ppx:resource">
       
    37     <xsl:param name="_indent" select="0"/>
    22     <xsl:param name="parent_path"/>
    38     <xsl:param name="parent_path"/>
    23     <xsl:variable name="resource_path">
    39     <xsl:variable name="resource_path">
    24       <xsl:value-of select="$parent_path"/>
    40       <xsl:value-of select="$parent_path"/>
    25       <xsl:text>.</xsl:text>
    41       <xsl:text>.</xsl:text>
    26       <xsl:value-of select="@name"/>
    42       <xsl:value-of select="@name"/>
    27     </xsl:variable>
    43     </xsl:variable>
    28     <xsl:apply-templates select="ppx:globalVars/ppx:variable[ppx:type/ppx:derived]">
    44     <xsl:apply-templates select="ppx:globalVars/ppx:variable[ppx:type/ppx:derived] | ppx:pouInstance | ppx:task/ppx:pouInstance">
    29       <xsl:with-param name="parent_path" select="$resource_path"/>
    45       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
    30     </xsl:apply-templates>
    46       <xsl:with-param name="parent_path">
    31     <xsl:apply-templates select="ppx:pouInstance | ppx:task/ppx:pouInstance">
    47         <xsl:value-of select="$resource_path"/>
    32       <xsl:with-param name="parent_path" select="$resource_path"/>
    48       </xsl:with-param>
    33     </xsl:apply-templates>
    49     </xsl:apply-templates>
    34   </xsl:template>
    50   </xsl:template>
    35   <xsl:template match="ppx:pouInstance">
    51   <xsl:template match="ppx:pouInstance">
       
    52     <xsl:param name="_indent" select="0"/>
    36     <xsl:param name="parent_path"/>
    53     <xsl:param name="parent_path"/>
    37     <xsl:variable name="pou_instance_path">
    54     <xsl:variable name="pou_instance_path">
    38       <xsl:value-of select="$parent_path"/>
    55       <xsl:value-of select="$parent_path"/>
    39       <xsl:text>.</xsl:text>
    56       <xsl:text>.</xsl:text>
    40       <xsl:value-of select="@name"/>
    57       <xsl:value-of select="@name"/>
    41     </xsl:variable>
    58     </xsl:variable>
    42     <xsl:choose>
    59     <xsl:choose>
    43       <xsl:when test="@typeName=$instance_type">
    60       <xsl:when test="@typeName=$instance_type">
    44         <instance>
    61         <xsl:value-of select="ns:AddInstance($pou_instance_path)"/>
    45           <xsl:attribute name="path">
       
    46             <xsl:value-of select="$pou_instance_path"/>
       
    47           </xsl:attribute>
       
    48         </instance>
       
    49       </xsl:when>
    62       </xsl:when>
    50       <xsl:otherwise>
    63       <xsl:otherwise>
    51         <ns:instance_definition>
    64         <xsl:variable name="type_name">
    52           <xsl:attribute name="name">
    65           <xsl:value-of select="@typeName"/>
    53             <xsl:value-of select="@typeName"/>
    66         </xsl:variable>
    54           </xsl:attribute>
    67         <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]">
    55           <xsl:attribute name="path">
    68           <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
    69           <xsl:with-param name="instance_path">
    56             <xsl:value-of select="$pou_instance_path"/>
    70             <xsl:value-of select="$pou_instance_path"/>
    57           </xsl:attribute>
    71           </xsl:with-param>
    58         </ns:instance_definition>
    72         </xsl:apply-templates>
    59       </xsl:otherwise>
    73       </xsl:otherwise>
    60     </xsl:choose>
    74     </xsl:choose>
    61   </xsl:template>
    75   </xsl:template>
    62   <xsl:template match="ppx:pou">
    76   <xsl:template match="ppx:pou">
       
    77     <xsl:param name="_indent" select="0"/>
    63     <xsl:param name="instance_path"/>
    78     <xsl:param name="instance_path"/>
    64     <xsl:apply-templates select="ppx:interface/*/ppx:variable[ppx:type/ppx:derived]">
    79     <xsl:apply-templates select="ppx:interface/*/ppx:variable[ppx:type/ppx:derived]">
    65       <xsl:with-param name="parent_path" select="$instance_path"/>
    80       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
    81       <xsl:with-param name="parent_path">
       
    82         <xsl:value-of select="$instance_path"/>
       
    83       </xsl:with-param>
    66     </xsl:apply-templates>
    84     </xsl:apply-templates>
    67   </xsl:template>
    85   </xsl:template>
    68   <xsl:template match="ppx:dataType">
    86   <xsl:template match="ppx:dataType">
       
    87     <xsl:param name="_indent" select="0"/>
    69     <xsl:param name="instance_path"/>
    88     <xsl:param name="instance_path"/>
    70     <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
    89     <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
    71       <xsl:with-param name="parent_path" select="$instance_path"/>
    90       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
    91       <xsl:with-param name="parent_path">
       
    92         <xsl:value-of select="$instance_path"/>
       
    93       </xsl:with-param>
    72     </xsl:apply-templates>
    94     </xsl:apply-templates>
    73   </xsl:template>
    95   </xsl:template>
    74   <xsl:template match="ppx:variable">
    96   <xsl:template match="ppx:variable">
       
    97     <xsl:param name="_indent" select="0"/>
    75     <xsl:param name="parent_path"/>
    98     <xsl:param name="parent_path"/>
    76     <xsl:variable name="variable_path">
    99     <xsl:variable name="variable_path">
    77       <xsl:value-of select="$parent_path"/>
   100       <xsl:value-of select="$parent_path"/>
    78       <xsl:text>.</xsl:text>
   101       <xsl:text>.</xsl:text>
    79       <xsl:value-of select="@name"/>
   102       <xsl:value-of select="@name"/>
    80     </xsl:variable>
   103     </xsl:variable>
    81     <xsl:apply-templates select="ppx:type/ppx:derived">
   104     <xsl:apply-templates select="ppx:type/ppx:derived">
    82       <xsl:with-param name="variable_path" select="$variable_path"/>
   105       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
   106       <xsl:with-param name="variable_path">
       
   107         <xsl:value-of select="$variable_path"/>
       
   108       </xsl:with-param>
    83     </xsl:apply-templates>
   109     </xsl:apply-templates>
    84   </xsl:template>
   110   </xsl:template>
    85   <xsl:template match="ppx:derived">
   111   <xsl:template match="ppx:derived">
       
   112     <xsl:param name="_indent" select="0"/>
    86     <xsl:param name="variable_path"/>
   113     <xsl:param name="variable_path"/>
    87     <xsl:choose>
   114     <xsl:choose>
    88       <xsl:when test="@name=$instance_type">
   115       <xsl:when test="@name=$instance_type">
    89         <instance>
   116         <xsl:value-of select="ns:AddInstance($variable_path)"/>
    90           <xsl:attribute name="path">
       
    91             <xsl:value-of select="$variable_path"/>
       
    92           </xsl:attribute>
       
    93         </instance>
       
    94       </xsl:when>
   117       </xsl:when>
    95       <xsl:otherwise>
   118       <xsl:otherwise>
    96         <ns:instance_definition>
   119         <xsl:variable name="type_name">
    97           <xsl:attribute name="name">
   120           <xsl:value-of select="@name"/>
    98             <xsl:value-of select="@name"/>
   121         </xsl:variable>
    99           </xsl:attribute>
   122         <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]">
   100           <xsl:attribute name="path">
   123           <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
   124           <xsl:with-param name="instance_path">
   101             <xsl:value-of select="$variable_path"/>
   125             <xsl:value-of select="$variable_path"/>
   102           </xsl:attribute>
   126           </xsl:with-param>
   103         </ns:instance_definition>
   127         </xsl:apply-templates>
   104       </xsl:otherwise>
   128       </xsl:otherwise>
   105     </xsl:choose>
   129     </xsl:choose>
   106   </xsl:template>
   130   </xsl:template>
   107   <xsl:template name="ppx:struct">
   131   <xsl:template match="ppx:struct">
       
   132     <xsl:param name="_indent" select="0"/>
   108     <xsl:param name="variable_path"/>
   133     <xsl:param name="variable_path"/>
   109     <xsl:for-each select="ppx:variable[ppx:type/ppx:derived or ppx:type/ppx:struct or ppx:type/ppx:array]">
   134     <xsl:for-each select="ppx:variable[ppx:type/ppx:derived or ppx:type/ppx:struct or ppx:type/ppx:array]">
   110       <xsl:variable name="element_path">
   135       <xsl:variable name="element_path">
   111         <xsl:value-of select="$variable_path"/>
   136         <xsl:value-of select="$variable_path"/>
   112         <xsl:text>.</xsl:text>
   137         <xsl:text>.</xsl:text>
   113         <xsl:value-of select="@name"/>
   138         <xsl:value-of select="@name"/>
   114       </xsl:variable>
   139       </xsl:variable>
   115       <xsl:apply-templates select="ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
   116         <xsl:with-param name="variable_path" select="$element_path"/>
       
   117       </xsl:apply-templates>
       
   118     </xsl:for-each>
   140     </xsl:for-each>
       
   141     <xsl:apply-templates select="ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
       
   142       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
   143       <xsl:with-param name="variable_path">
       
   144         <xsl:value-of select="$element_path"/>
       
   145       </xsl:with-param>
       
   146     </xsl:apply-templates>
   119   </xsl:template>
   147   </xsl:template>
   120   <xsl:template name="ppx:array">
   148   <xsl:template match="ppx:array">
       
   149     <xsl:param name="_indent" select="0"/>
   121     <xsl:param name="variable_path"/>
   150     <xsl:param name="variable_path"/>
   122     <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
   151     <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
   123       <xsl:with-param name="variable_path" select="$variable_path"/>
   152       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
   124     </xsl:apply-templates> 
   153       <xsl:with-param name="variable_path">
       
   154         <xsl:value-of select="$variable_path"/>
       
   155       </xsl:with-param>
       
   156     </xsl:apply-templates>
   125   </xsl:template>
   157   </xsl:template>
   126   <xsl:template match="pou_instance">
   158   <xsl:template match="pou_instance">
       
   159     <xsl:param name="_indent" select="0"/>
   127     <xsl:apply-templates>
   160     <xsl:apply-templates>
   128       <xsl:with-param name="instance_path" select="@pou_path"/>
   161       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
   162       <xsl:with-param name="instance_path">
       
   163         <xsl:value-of select="@pou_path"/>
       
   164       </xsl:with-param>
   129     </xsl:apply-templates>
   165     </xsl:apply-templates>
   130   </xsl:template>
   166   </xsl:template>
   131   <xsl:template match="datatype_instance">
   167   <xsl:template match="datatype_instance">
       
   168     <xsl:param name="_indent" select="0"/>
   132     <xsl:apply-templates>
   169     <xsl:apply-templates>
   133       <xsl:with-param name="instance_path" select="@datatype_path"/>
   170       <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       
   171       <xsl:with-param name="instance_path">
       
   172         <xsl:value-of select="@datatype_path"/>
       
   173       </xsl:with-param>
   134     </xsl:apply-templates>
   174     </xsl:apply-templates>
   135   </xsl:template>
   175   </xsl:template>
   136   <xsl:template match="text()"/>
       
   137 </xsl:stylesheet>
   176 </xsl:stylesheet>