svghmi/inline_svg.ysl2
branchsvghmi
changeset 3030 2d13a4379e2f
parent 3027 d660b1b6bf4f
child 3108 079419e7228d
equal deleted inserted replaced
3029:61b0491fe05b 3030:2d13a4379e2f
     8 
     8 
     9 
     9 
    10 // Identity template :
    10 // Identity template :
    11 //  - copy every attributes 
    11 //  - copy every attributes 
    12 //  - copy every sub-elements
    12 //  - copy every sub-elements
    13 template "@* | node()", mode="inline_svg" {
    13 
       
    14 svgtmpl "@*", mode="inline_svg" xsl:copy;
       
    15 
       
    16 template "node()", mode="inline_svg" {
    14   // use real xsl:copy instead copy-of alias from yslt.yml2
    17   // use real xsl:copy instead copy-of alias from yslt.yml2
    15   if "not(@id = $discardable_elements/@id)"
    18   if "not(@id = $discardable_elements/@id)"
    16       xsl:copy apply "@* | node()", mode="inline_svg";
    19       xsl:copy apply "@* | node()", mode="inline_svg";
    17 }
    20 }
    18 
    21 
    49 //       while keeping static decoration cloned
    52 //       while keeping static decoration cloned
    50 const "hmi_lists_descs", "$parsed_widgets/widget[@type = 'List']";
    53 const "hmi_lists_descs", "$parsed_widgets/widget[@type = 'List']";
    51 const "hmi_lists", "$hmi_elements[@id = $hmi_lists_descs/@id]";
    54 const "hmi_lists", "$hmi_elements[@id = $hmi_lists_descs/@id]";
    52 const "targets_not_to_unlink", "$hmi_lists/descendant-or-self::svg:*";
    55 const "targets_not_to_unlink", "$hmi_lists/descendant-or-self::svg:*";
    53 const "to_unlink", "$hmi_elements[not(@id = $hmi_pages/@id)]/descendant-or-self::svg:use";
    56 const "to_unlink", "$hmi_elements[not(@id = $hmi_pages/@id)]/descendant-or-self::svg:use";
    54 svgtmpl "svg:use", mode="inline_svg"
    57 
    55 {
    58 def "func:is_unlinkable" {
    56     param "seed";
    59     param "targetid";
       
    60     param "eltid";
       
    61     result "$eltid = $to_unlink/@id and not($targetid = $targets_not_to_unlink/@id)";
       
    62 }
       
    63 
       
    64 svgtmpl "svg:use", mode="inline_svg"{
    57     const "targetid","substring-after(@xlink:href,'#')";
    65     const "targetid","substring-after(@xlink:href,'#')";
    58     choose {
    66     choose {
    59         when "@id = $to_unlink/@id and not($targetid = $targets_not_to_unlink/@id)" {
    67         when "func:is_unlinkable($targetid, @id)" {
    60             call "unlink_clone" {
    68             call "unlink_clone" {
    61                 with "targetid", "$targetid";
    69                 with "targetid", "$targetid";
    62                 with "seed","$seed";
    70             }
    63             }
    71         }
    64         }
    72         otherwise xsl:copy apply "@*", mode="inline_svg";
    65         otherwise
       
    66             xsl:copy apply "@* | node()", mode="inline_svg";
       
    67     }
    73     }
    68 }
    74 }
    69 
    75 
    70 // to unlink a clone, an group containing a copy of target element is created
    76 // to unlink a clone, an group containing a copy of target element is created
    71 // that way, style and transforms can be preserved
    77 // that way, style and transforms can be preserved
    85 }
    91 }
    86 const "merge_use_attrs","exsl:node-set($_merge_use_attrs)";
    92 const "merge_use_attrs","exsl:node-set($_merge_use_attrs)";
    87 
    93 
    88 svgfunc "unlink_clone"{
    94 svgfunc "unlink_clone"{
    89     param "targetid";
    95     param "targetid";
    90     param "seed";
    96     param "seed","''";
    91     const "target", "//svg:*[@id = $targetid]";
    97     const "target", "//svg:*[@id = $targetid]";
    92     const "seeded_id","concat($seed, @id)";
    98     const "seeded_id" choose {
       
    99         when "string-length($seed) > 0" > «$seed»_«@id»
       
   100         otherwise value "@id";
       
   101     }
    93     g{
   102     g{
    94         attrib "id" value "$seeded_id";
   103         attrib "id" value "$seeded_id";
       
   104         attrib "original" value "@id";
       
   105 
    95         choose {
   106         choose {
    96             when "$target[self::svg:g]" {
   107             when "$target[self::svg:g]" {
    97                 foreach "@*[not(local-name() = $excluded_use_attrs/name | $merge_use_attrs)]"
   108                 foreach "@*[not(local-name() = $excluded_use_attrs/name | $merge_use_attrs)]"
    98                     attrib "{name()}" > «.»
   109                     attrib "{name()}" > «.»
    99 
   110 
   110                         if "@transform and $target/@transform" >  
   121                         if "@transform and $target/@transform" >  
   111                         > «$target/@transform»
   122                         > «$target/@transform»
   112                     }
   123                     }
   113 
   124 
   114                 apply "$target/*", mode="unlink_clone"{
   125                 apply "$target/*", mode="unlink_clone"{
   115                     with "seed","concat($seed, @id)";
   126                     with "seed","$seeded_id";
   116                 }
   127                 }
   117             }
   128             }
   118             otherwise {
   129             otherwise {
   119                 // include non excluded attributes
   130                 // include non excluded attributes
   120                 foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
   131                 foreach "@*[not(local-name() = $excluded_use_attrs/name)]"
   121                     attrib "{name()}" > «.»
   132                     attrib "{name()}" > «.»
   122 
   133 
   123                 apply "$target", mode="unlink_clone"{
   134                 apply "$target", mode="unlink_clone"{
   124                     with "seed","concat($seed, @id)";
   135                     with "seed","$seeded_id";
   125                 }
   136                 }
   126             }
   137             }
   127         }
   138         }
   128     }
   139     }
   129 }
   140 }
   131 // clone unlinking is really similar to deep-copy
   142 // clone unlinking is really similar to deep-copy
   132 // all nodes are sytematically copied
   143 // all nodes are sytematically copied
   133 svgtmpl "@id", mode="unlink_clone" {
   144 svgtmpl "@id", mode="unlink_clone" {
   134     param "seed";
   145     param "seed";
   135     attrib "id" > «$seed»_«.»
   146     attrib "id" > «$seed»_«.»
       
   147     attrib "original" > «.»
   136 }
   148 }
   137 
   149 
   138 svgtmpl "@*", mode="unlink_clone" xsl:copy;
   150 svgtmpl "@*", mode="unlink_clone" xsl:copy;
   139 
   151 
   140 svgtmpl "svg:use", mode="unlink_clone" {
   152 svgtmpl "svg:use", mode="unlink_clone" {
   141     param "seed";
   153     param "seed";
   142     apply "." mode="inline_svg" with "seed","concat($seed, '_')";
   154     const "targetid","substring-after(@xlink:href,'#')";
       
   155     choose {
       
   156         when "func:is_unlinkable($targetid, @id)" {
       
   157             call "unlink_clone" {
       
   158                 with "targetid", "$targetid";
       
   159                 with "seed","$seed";
       
   160             }
       
   161         }
       
   162         otherwise xsl:copy apply "@*", mode="unlink_clone" {
       
   163             with "seed","$seed";
       
   164         }
       
   165     }
   143 }
   166 }
   144 
   167 
   145 // copying widgets would have unwanted effect
   168 // copying widgets would have unwanted effect
   146 // instead widget is refered through a svg:use.
   169 // instead widget is refered through a svg:use.
   147 svgtmpl "svg:*", mode="unlink_clone" {
   170 svgtmpl "svg:*", mode="unlink_clone" {