Fix template conflict in XSLT with lxml>=4.9.0 again
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Mon, 16 Oct 2023 23:50:58 +0200
changeset 3868 e9807c28a788
parent 3867 a070a9681961
child 3869 b722c800b6c7
Fix template conflict in XSLT with lxml>=4.9.0 again

Earlier attempt was fixing conflict with -1.0 priority attribute,
as a side effect of such low priority, SFC Actions were not
editable anymore.

This time move template around instead of using explicit priority.
plcopen/pou_block_instances.xslt
plcopen/pou_block_instances.ysl2
plcopen/pou_variables.xslt
plcopen/pou_variables.ysl2
plcopen/variables_infos.xslt
plcopen/variables_infos.ysl2
--- a/plcopen/pou_block_instances.xslt	Mon Oct 16 23:35:47 2023 +0200
+++ b/plcopen/pou_block_instances.xslt	Mon Oct 16 23:50:58 2023 +0200
@@ -2,7 +2,7 @@
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:ppx="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns" exclude-result-prefixes="ns">
   <xsl:output method="xml"/>
   <xsl:template match="text()"/>
-  <xsl:template priority="-1.0" match="ppx:pou[ppx:body]|ppx:transition[ppx:body]|ppx:action[ppx:body]">
+  <xsl:template match="ppx:pou[ppx:body]|ppx:transition[ppx:body]|ppx:action[ppx:body]">
     <xsl:apply-templates select="ppx:body/*[self::ppx:FBD or self::ppx:LD or self::ppx:SFC]/*"/>
   </xsl:template>
   <xsl:template name="add_instance">
--- a/plcopen/pou_block_instances.ysl2	Mon Oct 16 23:35:47 2023 +0200
+++ b/plcopen/pou_block_instances.ysl2	Mon Oct 16 23:50:58 2023 +0200
@@ -7,7 +7,7 @@
     
     template "text()";
     
-    template "ppx:pou[ppx:body]|ppx:transition[ppx:body]|ppx:action[ppx:body]", priority="-1.0" {
+    template "ppx:pou[ppx:body]|ppx:transition[ppx:body]|ppx:action[ppx:body]" {
         apply "ppx:body/*[self::ppx:FBD or self::ppx:LD or self::ppx:SFC]/*";
     }
     
--- a/plcopen/pou_variables.xslt	Mon Oct 16 23:35:47 2023 +0200
+++ b/plcopen/pou_variables.xslt	Mon Oct 16 23:50:58 2023 +0200
@@ -202,6 +202,10 @@
       </xsl:with-param>
     </xsl:call-template>
   </xsl:template>
+  <xsl:template mode="var_class" match="*[self::ppx:type or self::ppx:baseType]/*">
+    <xsl:param name="default_class"/>
+    <xsl:value-of select="$default_class"/>
+  </xsl:template>
   <xsl:template mode="var_class" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:param name="default_class"/>
     <xsl:variable name="type_name" select="@name"/>
@@ -218,9 +222,8 @@
   <xsl:template mode="var_class" match="ppx:pou">
     <xsl:value-of select="@pouType"/>
   </xsl:template>
-  <xsl:template mode="var_class" priority="-1.0" match="*[self::ppx:type or self::ppx:baseType]/*">
-    <xsl:param name="default_class"/>
-    <xsl:value-of select="$default_class"/>
+  <xsl:template mode="var_type" match="*[self::ppx:type or self::ppx:baseType]/*">
+    <xsl:value-of select="local-name()"/>
   </xsl:template>
   <xsl:template mode="var_type" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:value-of select="@name"/>
@@ -241,8 +244,8 @@
   <xsl:template mode="var_type" match="*[self::ppx:type or self::ppx:baseType]/ppx:wstring">
     <xsl:text>WSTRING</xsl:text>
   </xsl:template>
-  <xsl:template mode="var_type" priority="-1.0" match="*[self::ppx:type or self::ppx:baseType]/*">
-    <xsl:value-of select="local-name()"/>
+  <xsl:template mode="var_edit" match="*[self::ppx:type or self::ppx:baseType]/*">
+    <xsl:text>false</xsl:text>
   </xsl:template>
   <xsl:template mode="var_edit" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:variable name="type_name" select="@name"/>
@@ -259,8 +262,8 @@
   <xsl:template mode="var_edit" match="*[self::ppx:type or self::ppx:baseType]/ppx:array">
     <xsl:apply-templates mode="var_edit" select="ppx:baseType"/>
   </xsl:template>
-  <xsl:template mode="var_edit" priority="-1.0" match="*[self::ppx:type or self::ppx:baseType]/*">
-    <xsl:text>false</xsl:text>
+  <xsl:template mode="var_debug" match="*[self::ppx:type or self::ppx:baseType]/*">
+    <xsl:text>true</xsl:text>
   </xsl:template>
   <xsl:template mode="var_debug" match="*[self::ppx:type or self::ppx:baseType]/ppx:derived">
     <xsl:variable name="type_name" select="@name"/>
@@ -283,7 +286,4 @@
   <xsl:template mode="var_debug" match="*[self::ppx:type or self::ppx:baseType]/ppx:struct">
     <xsl:text>false</xsl:text>
   </xsl:template>
-  <xsl:template mode="var_debug" priority="-1.0" match="*[self::ppx:type or self::ppx:baseType]/*">
-    <xsl:text>true</xsl:text>
-  </xsl:template>
 </xsl:stylesheet>
--- a/plcopen/pou_variables.ysl2	Mon Oct 16 23:35:47 2023 +0200
+++ b/plcopen/pou_variables.ysl2	Mon Oct 16 23:50:58 2023 +0200
@@ -170,6 +170,11 @@
         }
     }
     
+    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_class" {
+        param "default_class";
+        value "$default_class";
+    }
+  
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_class" {
         param "default_class";
         variable "type_name", "@name";
@@ -188,11 +193,10 @@
         value "@pouType";
     }
     
-    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_class", priority="-1.0" {
-        param "default_class";
-        value "$default_class";
-    }
-  
+    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_type" {
+        > «local-name()»
+    }
+    
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_type" {
         > «@name»
     }
@@ -214,8 +218,8 @@
         > WSTRING
     }
   
-    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_type", priority="-1.0" {
-        > «local-name()»
+    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_edit" {
+        > false
     }
     
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_edit" {
@@ -231,8 +235,8 @@
         apply "ppx:baseType", mode="var_edit";
     }
     
-    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_edit", priority="-1.0" {
-        > false
+    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_debug" {
+        > true
     }
     
     template "*[self::ppx:type or self::ppx:baseType]/ppx:derived", mode="var_debug" {
@@ -261,8 +265,4 @@
         > false
     }
     
-    template "*[self::ppx:type or self::ppx:baseType]/*", mode="var_debug", priority="-1.0" {
-        > true
-    }
-    
 }
--- a/plcopen/variables_infos.xslt	Mon Oct 16 23:35:47 2023 +0200
+++ b/plcopen/variables_infos.xslt	Mon Oct 16 23:50:58 2023 +0200
@@ -117,6 +117,12 @@
   <xsl:template mode="var_type" match="ppx:dataType">
     <xsl:apply-templates mode="var_type" select="ppx:baseType"/>
   </xsl:template>
+  <xsl:template mode="var_type" match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/*">
+    <xsl:variable name="name">
+      <xsl:value-of select="local-name()"/>
+    </xsl:variable>
+    <xsl:value-of select="ns:SetType($name)"/>
+  </xsl:template>
   <xsl:template mode="var_type" match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:struct">
     <xsl:apply-templates mode="var_type" select="ppx:variable"/>
   </xsl:template>
@@ -155,12 +161,6 @@
     </xsl:variable>
     <xsl:value-of select="ns:SetType($name)"/>
   </xsl:template>
-  <xsl:template mode="var_type" priority="-1.0" match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/*">
-    <xsl:variable name="name">
-      <xsl:value-of select="local-name()"/>
-    </xsl:variable>
-    <xsl:value-of select="ns:SetType($name)"/>
-  </xsl:template>
   <xsl:template mode="var_edit" match="*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:derived">
     <xsl:variable name="type_name">
       <xsl:value-of select="@name"/>
--- a/plcopen/variables_infos.ysl2	Mon Oct 16 23:35:47 2023 +0200
+++ b/plcopen/variables_infos.ysl2	Mon Oct 16 23:50:58 2023 +0200
@@ -117,6 +117,11 @@
     template "ppx:dataType", mode="var_type" {
         apply "ppx:baseType", mode="var_type";
     }
+
+    template "*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/*", mode="var_type" {
+        variable "name" > «local-name()»
+        value "ns:SetType($name)";
+    }
     
     template "*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:struct", mode="var_type" {
         apply "ppx:variable", mode="var_type";
@@ -152,10 +157,6 @@
         value "ns:SetType($name)";
     }
     
-    template "*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/*", mode="var_type", priority="-1.0" {
-        variable "name" > «local-name()»
-        value "ns:SetType($name)";
-    }
     
     template "*[self::ppx:type or self::ppx:baseType or self::ppx:returnType]/ppx:derived", mode="var_edit" {
         variable "type_name" > «@name»