SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element. svghmi
authorEdouard Tisserant
Thu, 14 May 2020 17:48:58 +0200
branchsvghmi
changeset 2968 556ef07a7e31
parent 2967 fc5fbf087b93
child 2969 88988edb2e93
SVGHMI: When unlinking a clone of a group, do not create additional group, but merge transformation and styles, and replace label. This allows svg:use based widgets to directly access elements of svg:use targeted element.
svghmi/inline_svg.ysl2
--- a/svghmi/inline_svg.ysl2	Thu May 14 17:48:15 2020 +0200
+++ b/svghmi/inline_svg.ysl2	Thu May 14 17:48:58 2020 +0200
@@ -69,15 +69,48 @@
 }
 const "excluded_use_attrs","exsl:node-set($_excluded_use_attrs)";
 
+const "_merge_use_attrs" {
+    name > transform
+    name > style
+}
+const "merge_use_attrs","exsl:node-set($_merge_use_attrs)";
+
 svgfunc "unlink_clone"{
+    const "targetid","substring-after(@xlink:href,'#')";
+    const "target", "//svg:*[@id = $targetid]";
     g{
-        // include non excluded attributes
-        foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
-            attrib "{name()}" > «.»
+        choose {
+            when "$target[self::svg:g]" {
+                foreach "@*[not(local-name() = $excluded_use_attrs/name | $merge_use_attrs)]"
+                    attrib "{name()}" > «.»
 
-        const "targetid","substring-after(@xlink:href,'#')";
-        apply "//svg:*[@id = $targetid]", mode="unlink_clone"{
-            with "seed","@id";
+                if "@style | $target/@style"
+                    attrib "style" {
+                        > «@style»
+                        if "@style and $target/@style" > ;
+                        > «$target/@style»
+                    }
+
+                if "@transform | $target/@transform"
+                    attrib "transform" {
+                        > «@transform»
+                        if "@transform and $target/@transform" >  
+                        > «$target/@transform»
+                    }
+
+                apply "$target/*", mode="unlink_clone"{
+                    with "seed","@id";
+                }
+            }
+            otherwise {
+                // include non excluded attributes
+                foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
+                    attrib "{name()}" > «.»
+
+                apply "$target", mode="unlink_clone"{
+                    with "seed","@id";
+                }
+            }
         }
     }
 }