Fixed pou tagname of instance path computing stylesheet
authorLaurent Bessard
Thu, 10 Oct 2013 09:43:52 +0200
changeset 1351 a546a63ce1bf
parent 1350 7280349a3375
child 1352 9ec4ac8e2955
Fixed pou tagname of instance path computing stylesheet
PLCControler.py
plcopen/instance_tagname.xslt
plcopen/instance_tagname.ysl2
--- a/PLCControler.py	Wed Oct 09 23:06:47 2013 +0200
+++ b/PLCControler.py	Thu Oct 10 09:43:52 2013 +0200
@@ -254,55 +254,30 @@
 #            Helpers object for generating instance tagname
 #-------------------------------------------------------------------------------
 
-class InstanceTagName(etree.XSLTExtension):
+class InstanceTagName:
 
     def __init__(self, controller):
-        etree.XSLTExtension.__init__(self)
         self.Controller = controller
-    
-    def GetTagName(self, infos):
-        return ""
-    
-    def execute(self, context, self_node, input_node, output_parent):
-        tagname_infos = etree.Element('infos')
-        self.process_children(context, tagname_infos)
-        tagname = etree.Element('tagname')
-        tagname.text = self.GetTagName(tagname_infos)
-        try:
-            output_parent.append(tagname)
-        except:
-            pass
-
-class ConfigTagName(InstanceTagName):
-    
-    def GetTagName(self, infos):
-        return self.Controller.ComputeConfigurationName(infos.get("name"))
-        
-class ResourceTagName(InstanceTagName):
-    
-    def GetTagName(self, infos):
-        return self.Controller.ComputeConfigurationResourceName(
-            infos.get("config_name"), infos.get("name"))
-
-class PouTagName(InstanceTagName):
-    
-    def GetTagName(self, infos):
-        return self.Controller.ComputePouName(infos.get("name"))
-
-class ActionTagName(InstanceTagName):
-    
-    def GetTagName(self, infos):
-        return self.Controller.ComputePouActionName(
-            infos.get("pou_name"), infos.get("name"))
-
-class TransitionTagName(InstanceTagName):
-    
-    def GetTagName(self, infos):
-        return self.Controller.ComputePouTransitionName(
-            infos.get("pou_name"), infos.get("name"))
-
-instance_tagname_xslt = etree.parse(
-    os.path.join(ScriptDirectory, "plcopen", "instance_tagname.xslt"))
+        self.TagName = None
+    
+    def GetTagName(self):
+        return self.TagName
+    
+    def ConfigTagName(self, context, *args):
+        self.TagName = self.Controller.ComputeConfigurationName(args[0][0])
+        
+    def ResourceTagName(self, context, *args):
+        self.TagName = self.Controller.ComputeConfigurationResourceName(args[0][0], args[1][0])
+
+    def PouTagName(self, context, *args):
+        #print "PouTagName", etree.tostring(args[0][0])
+        self.TagName = self.Controller.ComputePouName(args[0][0])
+
+    def ActionTagName(self, context, *args):
+        self.TagName = self.Controller.ComputePouActionName(args[0][0], args[0][1])
+
+    def TransitionTagName(self, context, *args):
+        self.TagName = self.Controller.ComputePouTransitionName(args[0][0], args[0][1])
 
 #-------------------------------------------------------------------------------
 #           Helpers object for generating pou block instances list
@@ -812,23 +787,24 @@
     
     def GetPouInstanceTagName(self, instance_path, debug = False):
         project = self.GetProject(debug)
+        factory = InstanceTagName(self)
+        
+        parser = etree.XMLParser()
+        parser.resolvers.add(LibraryResolver(self, debug))
         
         instance_tagname_xslt_tree = etree.XSLT(
-            instance_tagname_xslt, 
-            extensions = {
-                ("instance_tagname_ns", "instance_definition"): InstanceDefinition(self, debug),
-                ("instance_tagname_ns", "config_tagname"): ConfigTagName(self),
-                ("instance_tagname_ns", "resource_tagname"): ResourceTagName(self),
-                ("instance_tagname_ns", "pou_tagname"): PouTagName(self),
-                ("instance_tagname_ns", "action_tagname"): ActionTagName(self),
-                ("instance_tagname_ns", "transition_tagname"): TransitionTagName(self)})
-        
-        result = instance_tagname_xslt_tree(project, 
-                instance_path=etree.XSLT.strparam(instance_path)).getroot()
-        if result is not None:
-            return result.text
-        
-        return None
+            etree.parse(
+                os.path.join(ScriptDirectory, "plcopen", "instance_tagname.xslt"),
+                parser), 
+            extensions = {("instance_tagname_ns", name): getattr(factory, name)
+                          for name in ["ConfigTagName", "ResourceTagName",
+                                       "PouTagName", "ActionTagName", 
+                                       "TransitionTagName"]})
+        
+        instance_tagname_xslt_tree(project, 
+            instance_path=etree.XSLT.strparam(instance_path))
+        
+        return factory.GetTagName()
     
     def GetInstanceInfos(self, instance_path, debug = False):
         tagname = self.GetPouInstanceTagName(instance_path)
--- a/plcopen/instance_tagname.xslt	Wed Oct 09 23:06:47 2013 +0200
+++ b/plcopen/instance_tagname.xslt	Thu Oct 10 09:43:52 2013 +0200
@@ -1,12 +1,20 @@
-<xsl:stylesheet version="1.0"
-    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
-    xmlns:xhtml="http://www.w3.org/1999/xhtml"
-    xmlns:ns="instance_tagname_ns"
-    extension-element-prefixes="ns"
-    exclude-result-prefixes="ns">
+<?xml version="1.0"?>
+<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">
+  <xsl:output method="xml"/>
+  <xsl:variable name="space" select="'                                                                                                                                                                                                        '"/>
+  <xsl:param name="autoindent" select="4"/>
   <xsl:param name="instance_path"/>
+  <xsl:variable name="project">
+    <xsl:copy-of select="document('project')/project/*"/>
+  </xsl:variable>
+  <xsl:variable name="stdlib">
+    <xsl:copy-of select="document('stdlib')/stdlib/*"/>
+  </xsl:variable>
+  <xsl:variable name="extensions">
+    <xsl:copy-of select="document('extensions')/extensions/*"/>
+  </xsl:variable>
   <xsl:template name="element_name">
+    <xsl:param name="_indent" select="0"/>
     <xsl:param name="path"/>
     <xsl:choose>
       <xsl:when test="contains($path,'.')">
@@ -18,6 +26,7 @@
     </xsl:choose>
   </xsl:template>
   <xsl:template name="next_path">
+    <xsl:param name="_indent" select="0"/>
     <xsl:param name="path"/>
     <xsl:choose>
       <xsl:when test="contains($path,'.')">
@@ -26,12 +35,14 @@
     </xsl:choose>
   </xsl:template>
   <xsl:template match="ppx:project">
+    <xsl:param name="_indent" select="0"/>
     <xsl:variable name="config_name">
       <xsl:call-template name="element_name">
         <xsl:with-param name="path" select="$instance_path"/>
       </xsl:call-template>
     </xsl:variable>
     <xsl:apply-templates select="ppx:instances/ppx:configurations/ppx:configuration[@name=$config_name]">
+      <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       <xsl:with-param name="element_path">
         <xsl:call-template name="next_path">
           <xsl:with-param name="path" select="$instance_path"/>
@@ -40,41 +51,17 @@
     </xsl:apply-templates>
   </xsl:template>
   <xsl:template match="ppx:configuration">
+    <xsl:param name="_indent" select="0"/>
     <xsl:param name="element_path"/>
     <xsl:choose>
       <xsl:when test="$element_path!=''">
         <xsl:variable name="child_name">
-	      <xsl:call-template name="element_name">
-	        <xsl:with-param name="path" select="$element_path"/>
-	      </xsl:call-template>
-	    </xsl:variable>
+          <xsl:call-template name="element_name">
+            <xsl:with-param name="path" select="$element_path"/>
+          </xsl:call-template>
+        </xsl:variable>
         <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]">
-          <xsl:with-param name="element_path">
-            <xsl:call-template name="next_path">
-		      <xsl:with-param name="path" select="$element_path"/>
-		    </xsl:call-template>
-		  </xsl:with-param>
-        </xsl:apply-templates>
-      </xsl:when>
-      <xsl:otherwise>
-        <ns:config_tagname>
-          <xsl:attribute name="name">
-            <xsl:value-of select="@name"/>
-          </xsl:attribute>
-        </ns:config_tagname>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-  <xsl:template match="ppx:resource">
-    <xsl:param name="element_path"/>
-    <xsl:choose>
-      <xsl:when test="$element_path!=''">
-	    <xsl:variable name="child_name">
-	      <xsl:call-template name="element_name">
-	        <xsl:with-param name="path" select="$element_path"/>
-	      </xsl:call-template>
-	    </xsl:variable>
-        <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]">
+          <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
           <xsl:with-param name="element_path">
             <xsl:call-template name="next_path">
               <xsl:with-param name="path" select="$element_path"/>
@@ -83,123 +70,127 @@
         </xsl:apply-templates>
       </xsl:when>
       <xsl:otherwise>
-        <ns:resource_tagname>
-          <xsl:attribute name="name">
-            <xsl:value-of select="@name"/>
-          </xsl:attribute>
-          <xsl:attribute name="config_name">
-            <xsl:value-of select="ancestor::ppx:configuration/@name"/>
-          </xsl:attribute>
-        </ns:resource_tagname>
+        <xsl:value-of select="ns:ConfigTagName(@name)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  <xsl:template match="ppx:resource">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:param name="element_path"/>
+    <xsl:choose>
+      <xsl:when test="$element_path!=''">
+        <xsl:variable name="child_name">
+          <xsl:call-template name="element_name">
+            <xsl:with-param name="path">
+              <xsl:value-of select="$element_path"/>
+            </xsl:with-param>
+          </xsl:call-template>
+        </xsl:variable>
+        <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]">
+          <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+          <xsl:with-param name="element_path">
+            <xsl:call-template name="next_path">
+              <xsl:with-param name="path" select="$element_path"/>
+            </xsl:call-template>
+          </xsl:with-param>
+        </xsl:apply-templates>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:value-of select="ns:ResourceTagName(ancestor::ppx:configuration/@name, @name)"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
   <xsl:template match="ppx:pouInstance">
+    <xsl:param name="_indent" select="0"/>
     <xsl:param name="element_path"/>
-    <ns:instance_definition>
-      <xsl:attribute name="name">
-        <xsl:value-of select="@typeName"/>
-      </xsl:attribute>
-      <xsl:attribute name="path">
-        <xsl:value-of select="$element_path"/>
-      </xsl:attribute>
-    </ns:instance_definition>
+    <xsl:variable name="type_name">
+      <xsl:value-of select="@typeName"/>
+    </xsl:variable>
+    <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]">
+      <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+      <xsl:with-param name="element_path" select="$element_path"/>
+    </xsl:apply-templates>
   </xsl:template>
   <xsl:template match="ppx:pou">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:param name="element_path"/>
+    <xsl:choose>
+      <xsl:when test="$element_path!=''">
+        <xsl:variable name="child_name">
+          <xsl:call-template name="element_name">
+            <xsl:with-param name="path" select="$element_path"/>
+          </xsl:call-template>
+        </xsl:variable>
+        <xsl:apply-templates select="ppx:interface/*/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
+          <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+          <xsl:with-param name="element_path">
+            <xsl:call-template name="next_path">
+              <xsl:with-param name="path" select="$element_path"/>
+            </xsl:call-template>
+          </xsl:with-param>
+        </xsl:apply-templates>
+        <xsl:apply-templates select="ppx:actions/ppx:action[@name=$child_name] | ppx:transitions/ppx:transition[@name=$child_name]">
+          <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+        </xsl:apply-templates>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:variable name="name">
+          <xsl:value-of select="@name"/>
+        </xsl:variable>
+        <xsl:value-of select="ns:PouTagName($name)"/>
+      </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+  <xsl:template match="ppx:action">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:value-of select="ns:ActionTagName(ancestor::ppx:pou/@name, @name)"/>
+  </xsl:template>
+  <xsl:template match="ppx:transition">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:value-of select="ns:TransitionTagName(ancestor::ppx:pou/@name, @name)"/>
+  </xsl:template>
+  <xsl:template match="ppx:dataType">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:param name="element_path"/>
+    <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
+      <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+      <xsl:with-param name="element_path" select="$element_path"/>
+    </xsl:apply-templates>
+  </xsl:template>
+  <xsl:template match="ppx:derived">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:param name="element_path"/>
+    <xsl:variable name="type_name">
+      <xsl:value-of select="@name"/>
+    </xsl:variable>
+    <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]">
+      <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+      <xsl:with-param name="element_path" select="$element_path"/>
+    </xsl:apply-templates>
+  </xsl:template>
+  <xsl:template match="ppx:array">
+    <xsl:param name="_indent" select="0"/>
+    <xsl:param name="element_path"/>
+    <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
+      <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
+      <xsl:with-param name="element_path" select="$element_path"/>
+    </xsl:apply-templates>
+  </xsl:template>
+  <xsl:template match="ppx:struct">
+    <xsl:param name="_indent" select="0"/>
     <xsl:param name="element_path"/>
     <xsl:variable name="child_name">
       <xsl:call-template name="element_name">
         <xsl:with-param name="path" select="$element_path"/>
       </xsl:call-template>
     </xsl:variable>
-    <xsl:apply-templates select="ppx:interface/*/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
+    <xsl:apply-templates select="ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
+      <xsl:with-param name="_indent" select="$_indent + (1) * $autoindent"/>
       <xsl:with-param name="element_path">
         <xsl:call-template name="next_path">
           <xsl:with-param name="path" select="$element_path"/>
         </xsl:call-template>
       </xsl:with-param>
     </xsl:apply-templates>
-    <xsl:apply-templates select="ppx:actions/ppx:action[@name=$child_name]"/>
-    <xsl:apply-templates select="ppx:transitions/ppx:transition[@name=$child_name]"/>
   </xsl:template>
-  <xsl:template match="ppx:action">
-    <ns:action_tagname>
-      <xsl:attribute name="name">
-        <xsl:value-of select="@name"/>
-      </xsl:attribute>
-      <xsl:attribute name="pou_name">
-        <xsl:value-of select="ancestor::ppx:pou/@name"/>
-      </xsl:attribute>
-    </ns:action_tagname>
-  </xsl:template>
-  <xsl:template match="ppx:transition">
-    <ns:transition_tagname>
-      <xsl:attribute name="name">
-        <xsl:value-of select="@name"/>
-      </xsl:attribute>
-      <xsl:attribute name="pou_name">
-        <xsl:value-of select="ancestor::ppx:pou/@name"/>
-      </xsl:attribute>
-    </ns:transition_tagname>
-  </xsl:template>
-  <xsl:template name="ppx:dataType">
-    <xsl:param name="element_path"/>
-    <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
-      <xsl:with-param name="element_path" select="element_path"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  <xsl:template match="ppx:derived">
-    <xsl:param name="element_path"/>
-    <ns:instance_definition>
-      <xsl:attribute name="name">
-        <xsl:value-of select="@name"/>
-      </xsl:attribute>
-      <xsl:attribute name="path">
-        <xsl:value-of select="$element_path"/>
-      </xsl:attribute>
-    </ns:instance_definition>
-  </xsl:template>
-  <xsl:template match="array">
-    <xsl:param name="element_path"/>
-    <xsl:apply-templates select="ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
-      <xsl:with-param name="element_path" select="element_path"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  <xsl:template match="struct">
-    <xsl:param name="element_path"/>
-    <xsl:variable name="child_name">
-      <xsl:call-template name="element_name">
-        <xsl:with-param name="path" select="$element_path"/>
-      </xsl:call-template>
-    </xsl:variable>
-    <xsl:variable name="next_child_path">
-      <xsl:call-template name="next_path">
-        <xsl:with-param name="path" select="$element_path"/>
-      </xsl:call-template>
-    </xsl:variable>
-    <xsl:apply-templates select="ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]">
-      <xsl:with-param name="element_path" select="element_path"/>
-    </xsl:apply-templates>
-  </xsl:template>
-  <xsl:template match="pou_instance">
-    <xsl:choose>
-      <xsl:when test="@pou_path!=''">
-        <xsl:apply-templates>
-          <xsl:with-param name="element_path" select="@pou_path"/>
-        </xsl:apply-templates>        
-      </xsl:when>
-      <xsl:otherwise>
-        <ns:pou_tagname>
-          <xsl:attribute name="name">
-            <xsl:value-of select="ppx:pou/@name"/>
-          </xsl:attribute>
-        </ns:pou_tagname>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-  <xsl:template match="datatype_instance">
-    <xsl:apply-templates>
-      <xsl:with-param name="element_path" select="@datatype_path"/>
-    </xsl:apply-templates>
-  </xsl:template>
-</xsl:stylesheet>
\ No newline at end of file
+</xsl:stylesheet>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plcopen/instance_tagname.ysl2	Thu Oct 10 09:43:52 2013 +0200
@@ -0,0 +1,186 @@
+include yslt.yml2
+estylesheet xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
+            xmlns:xhtml="http://www.w3.org/1999/xhtml"
+            xmlns:ns="instance_tagname_ns" 
+            extension-element-prefixes="ns" 
+            exclude-result-prefixes="ns" {
+    
+    param "instance_path";
+    
+    variable "project" {
+        copy "document('project')/project/*";
+    }
+    
+    variable "stdlib" {
+        copy "document('stdlib')/stdlib/*";
+    }
+    variable "extensions" {
+        copy "document('extensions')/extensions/*";
+    }
+    
+    function "element_name" {
+        param "path";
+        choose {
+            when "contains($path,'.')" > «substring-before($path,'.')»
+            otherwise > «$path»
+        }
+    }
+    
+    function "next_path" {
+        param "path";
+        choose {
+            when "contains($path,'.')" > «substring-after($path,'.')»
+        }
+    }
+    
+    template "ppx:project" {
+        variable "config_name" {
+            call "element_name" {
+                with "path", "$instance_path";
+            }
+        }
+        apply "ppx:instances/ppx:configurations/ppx:configuration[@name=$config_name]" {
+            with "element_path" {
+                call "next_path" {
+                    with "path", "$instance_path";
+                }
+            }
+        }
+    }
+    
+    template "ppx:configuration" {
+        param "element_path";
+        choose {
+            when "$element_path!=''" {
+                variable "child_name" {
+                    call "element_name" {
+                        with "path", "$element_path";
+                    }
+                }
+                apply "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]" {
+                    with "element_path" {
+                        call "next_path" {
+                            with "path", "$element_path";
+                        }
+                    }
+                }
+            }
+            otherwise {
+                value "ns:ConfigTagName(@name)";
+            }
+        }
+    }
+    
+    template "ppx:resource" {
+        param "element_path";
+        choose {
+            when "$element_path!=''" {
+                variable "child_name" {
+                    call "element_name" {
+                        with "path" > «$element_path»
+                    }
+                }
+                apply "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]" {
+                    with "element_path" {
+                        call "next_path" {
+                            with "path", "$element_path";
+                        }
+                    }
+                }
+            }
+            otherwise {
+                value "ns:ResourceTagName(ancestor::ppx:configuration/@name, @name)";
+            }
+        }
+    }
+    
+    template "ppx:pouInstance" {
+        param "element_path";
+        variable "type_name" > «@typeName»
+        apply """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                 exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
+                 exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                 exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
+                 exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                 exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
+            with "element_path", "$element_path";
+        }
+    }
+    
+    template "ppx:pou" {
+        param "element_path";
+        choose {
+            when "$element_path!=''" {
+                variable "child_name" {
+                    call "element_name" {
+                        with "path", "$element_path";
+                    }
+                }
+                apply "ppx:interface/*/ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
+                    with "element_path" {
+                        call "next_path" {
+                            with "path", "$element_path";
+                        }
+                    }
+                }
+                apply "ppx:actions/ppx:action[@name=$child_name] | ppx:transitions/ppx:transition[@name=$child_name]";
+            }
+            otherwise {
+                variable "name" > «@name»
+                value "ns:PouTagName($name)";
+            }
+        }
+    }
+    
+    template "ppx:action" {
+        value "ns:ActionTagName(ancestor::ppx:pou/@name, @name)";
+    }
+    
+    template "ppx:transition" {
+        value "ns:TransitionTagName(ancestor::ppx:pou/@name, @name)";
+    }
+    
+    template "ppx:dataType" {
+        param "element_path";
+        apply "ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
+            with "element_path", "$element_path";
+        }
+    }
+    
+    template "ppx:derived" {
+        param "element_path";
+        variable "type_name" > «@name»
+        apply """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                 exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
+                 exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                 exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
+                 exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
+                 exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""" {
+            with "element_path", "$element_path";
+        }
+    }
+    
+    template "ppx:array" {
+        param "element_path";
+        apply "ppx:baseType/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
+            with "element_path", "$element_path";
+        }
+    }
+    
+    template "ppx:struct" {
+        param "element_path";
+        variable "child_name" {
+            call "element_name" {
+                with "path", "$element_path";
+            }
+        }
+        apply "ppx:variable[@name=$child_name]/ppx:type/*[self::ppx:derived or self::ppx:struct or self::ppx:array]" {
+            with "element_path" {
+                call "next_path" {
+                    with "path", "$element_path";
+                }
+            }
+        }
+    }
+    
+}