|
1 in xsl decl labels(*ptr, name="defs_by_labels") alias call-template { |
|
2 with "hmi_element", "$hmi_element"; |
|
3 with "labels"{text *ptr}; |
|
4 }; |
|
5 |
|
6 in xsl decl optional_labels(*ptr, name="defs_by_labels") alias call-template { |
|
7 with "hmi_element", "$hmi_element"; |
|
8 with "labels"{text *ptr}; |
|
9 with "mandatory","'no'"; |
|
10 }; |
|
11 |
|
12 template "svg:*", mode="hmi_elements" { |
|
13 const "widget", "func:parselabel(@inkscape:label)/widget"; |
|
14 const "eltid","@id"; |
|
15 | "«@id»": { |
|
16 | type: "«$widget/@type»", |
|
17 | args: [ |
|
18 foreach "$widget/arg" |
|
19 | "«@value»"`if "position()!=last()" > ,` |
|
20 | ], |
|
21 | indexes: [ |
|
22 foreach "$widget/path" { |
|
23 choose { |
|
24 when "not(@index)" { |
|
25 warning > Widget «$widget/@type» id="«$eltid»" : No match for path "«@value»" in HMI tree |
|
26 } |
|
27 otherwise { |
|
28 | «@index»`if "position()!=last()" > ,` |
|
29 } |
|
30 } |
|
31 } |
|
32 | ], |
|
33 | element: id("«@id»"), |
|
34 apply "$widget", mode="widget_defs" with "hmi_element","."; |
|
35 | }`if "position()!=last()" > ,` |
|
36 } |
|
37 |
|
38 |
|
39 function "defs_by_labels" { |
|
40 param "labels","''"; |
|
41 param "mandatory","'yes'"; |
|
42 param "hmi_element"; |
|
43 const "widget_type","@type"; |
|
44 foreach "str:split($labels)" { |
|
45 const "name","."; |
|
46 const "elt_id","$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"; |
|
47 choose { |
|
48 when "not($elt_id)" { |
|
49 if "$mandatory='yes'" { |
|
50 // TODO FIXME error > «$widget_type» widget must have a «$name» element |
|
51 warning > «$widget_type» widget must have a «$name» element |
|
52 } |
|
53 // otherwise produce nothing |
|
54 } |
|
55 otherwise { |
|
56 | «$name»_elt: id("«$elt_id»"), |
|
57 } |
|
58 } |
|
59 } |
|
60 } |
|
61 |
|
62 def "func:escape_quotes" { |
|
63 param "txt"; |
|
64 // have to use a python string to enter escaped quote |
|
65 const "frst", !"substring-before($txt,'\"')"!; |
|
66 const "frstln", "string-length($frst)"; |
|
67 choose { |
|
68 when "$frstln > 0 and string-length($txt) > $frstln" { |
|
69 result !"concat($frst,'\\\"',func:escape_quotes(substring-after($txt,'\"')))"!; |
|
70 } |
|
71 otherwise { |
|
72 result "$txt"; |
|
73 } |
|
74 } |
|
75 } |
|
76 |