|
1 include yslt_noindent.yml2 |
|
2 |
|
3 in xsl decl svgtmpl(match, xmlns="http://www.w3.org/2000/svg") alias template; |
|
4 |
|
5 istylesheet |
|
6 /* From Inkscape */ |
|
7 xmlns:dc="http://purl.org/dc/elements/1.1/" |
|
8 xmlns:cc="http://creativecommons.org/ns#" |
|
9 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" |
|
10 xmlns:svg="http://www.w3.org/2000/svg" |
|
11 xmlns:xlink="http://www.w3.org/1999/xlink" |
|
12 xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" |
|
13 xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" |
|
14 |
|
15 /* Namespace to invoke python code */ |
|
16 xmlns:ns="beremiz" |
|
17 |
|
18 extension-element-prefixes="ns func exsl regexp str dyn" |
|
19 exclude-result-prefixes="ns func exsl regexp str dyn" { |
|
20 |
|
21 const "hmi_elements", "//svg:*[starts-with(@inkscape:label, 'HMI:')]"; |
|
22 const "widgetparams", "ns:GetWidgetParams()"; |
|
23 |
|
24 const "indexed_hmitree", "/.."; // compatibility with parse_labels.ysl2 |
|
25 include parse_labels.ysl2 |
|
26 const "_parsed_widgets" apply "$hmi_elements", mode="parselabel"; |
|
27 const "parsed_widgets","exsl:node-set($_parsed_widgets)"; |
|
28 |
|
29 const "svg_widget", "$parsed_widgets/widget[1]"; |
|
30 const "svg_widget_type", "$svg_widget/@type"; |
|
31 const "svg_widget_path", "$svg_widget/@path"; |
|
32 const "svg_widget_count", "count($parsed_widgets/widget)"; |
|
33 |
|
34 // Templates to change label paths(s) |
|
35 template "@* | node()", mode="replace_params" { |
|
36 xsl:copy apply "@* | node()", mode="replace_params"; |
|
37 } |
|
38 |
|
39 template "arg", mode="replace_params"; |
|
40 template "path", mode="replace_params"; |
|
41 template "widget", mode="replace_params" { |
|
42 xsl:copy { |
|
43 apply "@* | node()", mode="replace_params"; |
|
44 copy "$widgetparams/*"; |
|
45 }; |
|
46 } |
|
47 |
|
48 // all attribs are usually copied |
|
49 svgtmpl "@*", mode="inline_svg" xsl:copy; |
|
50 |
|
51 // except labels, ignored |
|
52 svgtmpl "@inkscape:label[starts-with(., 'HMI:')]", mode="inline_svg"; |
|
53 |
|
54 template "node()", mode="inline_svg" xsl:copy { |
|
55 |
|
56 // in case this node widget's main element inject label |
|
57 if "@id = $svg_widget/@id" { |
|
58 const "substituted_widget" apply "$svg_widget", mode="replace_params"; |
|
59 const "substituted_widget_ns", "exsl:node-set($substituted_widget)"; |
|
60 const "new_label" apply "$substituted_widget_ns", mode="genlabel"; |
|
61 attrib "inkscape:label" > «$new_label» |
|
62 } |
|
63 // all nodes are copied as well |
|
64 apply "@* | node()", mode="inline_svg"; |
|
65 } |
|
66 |
|
67 template "/" { |
|
68 comment > Widget dropped in Inkscape from Beremiz |
|
69 |
|
70 choose { |
|
71 when "$svg_widget_count < 1" |
|
72 error > No widget detected on selected SVG |
|
73 when "$svg_widget_count > 1" |
|
74 error > Multiple widget DnD not yet supported |
|
75 } |
|
76 |
|
77 apply "/", mode="inline_svg"; |
|
78 } |
|
79 } |