Laurent@1348: include yslt.yml2
Laurent@1348: estylesheet xmlns:ppx="http://www.plcopen.org/xml/tc6_0201"
Laurent@1348:             xmlns:xhtml="http://www.w3.org/1999/xhtml"
Laurent@1348:             xmlns:ns="pou_vars_ns" 
Laurent@1348:             extension-element-prefixes="ns" 
Laurent@1348:             exclude-result-prefixes="ns" {
Laurent@1348:     
Laurent@1348:     template "text()";
Laurent@1348:     template "text()", mode="var_class";
Laurent@1348:     template "text()", mode="var_type";
Laurent@1348:     template "text()", mode="var_edit";
Laurent@1348:     template "text()", mode="var_debug";
Laurent@1348:     
Laurent@1348:     variable "project" {
Laurent@1348:         copy "document('project')/project/*";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     variable "stdlib" {
Laurent@1348:         copy "document('stdlib')/stdlib/*";
Laurent@1348:     }
Laurent@1348:     variable "extensions" {
Laurent@1348:         copy "document('extensions')/extensions/*";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     function "add_root" {
Laurent@1348:         param "class";
Laurent@1348:         param "type";
Laurent@1348:         param "edit" > true
Laurent@1348:         param "debug" > true
Laurent@1348:         value "ns:SetRoot($class, $type, $edit, $debug)";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:pou" {
Laurent@1348:         call "add_root" {
Laurent@1348:             with "class" > «@pouType»
Laurent@1348:             with "type" > «@name»
Laurent@1348:         }
Laurent@1348:         apply "ppx:interface";
Laurent@1348:         apply "ppx:actions/ppx:action | ppx:transitions/ppx:transition", mode="variable_list";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:action" {
Laurent@1348:         call "add_root" {
Laurent@1348:             with "class" > action
Laurent@1348:         }
Laurent@1348:         apply "ancestor::ppx:pou/child::ppx:interface";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:transition" {
Laurent@1348:         call "add_root" {
Laurent@1348:             with "class" > transition
Laurent@1348:         }
Laurent@1348:         apply "ancestor::ppx:pou/child::ppx:interface";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:configuration" {
Laurent@1348:         call "add_root" {
Laurent@1348:             with "class" > configuration
Laurent@1348:             with "debug" > false
Laurent@1348:         }
Laurent@1348:         apply "ppx:resource", mode="variable_list";
Laurent@1348:         apply "ppx:globalVars";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:resource" {
Laurent@1348:         call "add_root" {
Laurent@1348:             with "class" > resource
Laurent@1348:             with "debug" > false
Laurent@1348:         }
Laurent@1348:         apply "ppx:pouInstance | ppx:task/ppx:pouInstance",  mode="variable_list";
Laurent@1348:         apply "ppx:globalVars";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     function "variables_infos" {
Laurent@1348:         param "var_class";
Laurent@1348:         foreach "ppx:variable" {
Laurent@1348:             variable "class" {
Laurent@1348:                 apply "ppx:type", mode="var_class" {
Laurent@1348:                     with "default_class" > «$var_class»
Laurent@1348:                 }
Laurent@1348:             }
Laurent@1348:             variable "type" {
Laurent@1348:                 apply"ppx:type", mode="var_type";
Laurent@1348:             }
Laurent@1348:             variable "edit" {
Laurent@1348:                 apply "ppx:type", mode="var_edit";
Laurent@1348:             }
Laurent@1348:             variable "debug" {
Laurent@1348:                 apply "ppx:type", mode="var_debug";
Laurent@1348:             }
Laurent@1348:             value "ns:AddVariable(@name, $class, $type, $edit, $debug)";
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:localVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > Local
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:globalVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > Global
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:externalVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > External
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:tempVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > Temp
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:inputVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > Input
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:outputVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > Output
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:inOutVars" {
Laurent@1348:         call "variables_infos" {
Laurent@1348:             with "var_class" > InOut
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     function "add_variable" {
Laurent@1348:         param "name";
Laurent@1348:         param "class";
Laurent@1348:         param "type";
Laurent@1348:         param "edit" > true
Laurent@1348:         param "debug" > true
Laurent@1348:         value "ns:AddVariable($name, $class, $type, $edit, $debug)";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:action", mode="variable_list" {
Laurent@1348:         call "add_variable" {
Laurent@1348:             with "name" > «@name»
Laurent@1348:             with "class" > action
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:transition", mode="variable_list" {
Laurent@1348:         call "add_variable" {
Laurent@1348:             with "name" > «@name»
Laurent@1348:             with "class" > transition
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:resource", mode="variable_list" {
Laurent@1348:         call "add_variable" {
Laurent@1348:             with "name" > «@name»
Laurent@1348:             with "class" > resource
Laurent@1348:             with "debug" > false
Laurent@1348:         } 
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:pouInstance", mode="variable_list" {
Laurent@1348:         call "add_variable" {
Laurent@1348:             with "name" > «@name»
Laurent@1348:             with "class" > program
Laurent@1348:             with "type" > «@typeName»
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_class" {
Laurent@1348:         param "default_class";
Laurent@1348:         variable "type_name", "@name";
Laurent@1348:         variable "pou_infos" {
Laurent@1348:             copy """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
Laurent@1348:                     exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
Laurent@1348:                     exsl:node-set($extensions)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]""";
Laurent@1348:         }
Laurent@1348:         choose {
Laurent@1348:             when "$pou_infos != ''" {
Laurent@1348:                 apply "exsl:node-set($pou_infos)", mode="var_class";
Laurent@1348:             }
Laurent@1348:             otherwise {
Laurent@1348:                 value "$default_class"
Laurent@1348:             }
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:pou", mode="var_class" {
Laurent@1348:         value "@pouType";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/*" mode="var_class" {
Laurent@1348:         param "default_class";
Laurent@1348:         value "$default_class";
Laurent@1348:     }
Laurent@1348:   
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_type" {
Laurent@1348:         > «@name»
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:array", mode="var_type" {
Laurent@1348:         > ARRAY [
Laurent@1348:         foreach "ppx:dimension" {
Laurent@1348:             > «@lower»..«@upper»
Laurent@1348:         }
Laurent@1348:         > ] OF 
Laurent@1348:         apply "ppx:baseType", mode="var_type";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:string", mode="var_type" {
Laurent@1348:         > STRING
Laurent@1348:     }
Laurent@1348:   
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:wstring", mode="var_type" {
Laurent@1348:         > WSTRING
Laurent@1348:     }
Laurent@1348:   
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_type" {
Laurent@1348:         > «local-name()»
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_edit" {
Laurent@1348:         variable "type_name", "@name";
Laurent@1348:         variable "pou_infos" {
Laurent@1348:             copy "exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name]";
Laurent@1348:         }
Laurent@1348:         choose {
Laurent@1348:             when "$pou_infos != ''" > true
Laurent@1348:             otherwise > false
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:array", mode="var_edit" {
Laurent@1348:         apply "ppx:baseType", mode="var_edit";
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_edit" {
Laurent@1348:         > false
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_debug" {
Laurent@1348:         variable "type_name", "@name";
Laurent@1348:         variable "datatype_infos" {
Laurent@1348:             copy """exsl:node-set($project)/ppx:project/ppx:types/ppx:pous/ppx:pou[@name=$type_name] |
Laurent@1348:                     exsl:node-set($project)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
Laurent@1348:                     exsl:node-set($stdlib)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name] |
Laurent@1348:                     exsl:node-set($extensions)/ppx:project/ppx:types/ppx:dataTypes/ppx:dataType[@name=$type_name]""";
Laurent@1348:         }
Laurent@1348:         choose {
Laurent@1348:             when "$datatype_infos != ''" {
Laurent@1348:                 apply "exsl:node-set($datatype_infos)", mode="var_debug";
Laurent@1348:             }
Laurent@1348:             otherwise > false
Laurent@1348:         }
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "ppx:pou", mode="var_debug" {
Laurent@1348:         > true
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:array", mode="var_debug" {
Laurent@1348:         > false
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/ppx:struct", mode="var_debug" {
Laurent@1348:         > false
Laurent@1348:     }
Laurent@1348:     
Laurent@1348:     template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_debug" {
Laurent@1348:         > true
Laurent@1348:     }
Laurent@1348:     
Laurent@1348: }