|
1 <?xml version="1.0"?> |
|
2 <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:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn"> |
|
3 <xsl:output method="xml"/> |
|
4 <xsl:variable name="svg" select="/svg:svg"/> |
|
5 <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/> |
|
6 <xsl:template mode="parselabel" match="*"> |
|
7 <xsl:variable name="label" select="@inkscape:label"/> |
|
8 <xsl:variable name="id" select="@id"/> |
|
9 <xsl:variable name="description" select="substring-after($label,'HMI:')"/> |
|
10 <xsl:variable name="_args" select="substring-before($description,'@')"/> |
|
11 <xsl:variable name="args"> |
|
12 <xsl:choose> |
|
13 <xsl:when test="$_args"> |
|
14 <xsl:value-of select="$_args"/> |
|
15 </xsl:when> |
|
16 <xsl:otherwise> |
|
17 <xsl:value-of select="$description"/> |
|
18 </xsl:otherwise> |
|
19 </xsl:choose> |
|
20 </xsl:variable> |
|
21 <xsl:variable name="_type" select="substring-before($args,':')"/> |
|
22 <xsl:variable name="type"> |
|
23 <xsl:choose> |
|
24 <xsl:when test="$_type"> |
|
25 <xsl:value-of select="$_type"/> |
|
26 </xsl:when> |
|
27 <xsl:otherwise> |
|
28 <xsl:value-of select="$args"/> |
|
29 </xsl:otherwise> |
|
30 </xsl:choose> |
|
31 </xsl:variable> |
|
32 <xsl:if test="$type"> |
|
33 <widget> |
|
34 <xsl:attribute name="id"> |
|
35 <xsl:value-of select="$id"/> |
|
36 </xsl:attribute> |
|
37 <xsl:attribute name="type"> |
|
38 <xsl:value-of select="$type"/> |
|
39 </xsl:attribute> |
|
40 <xsl:for-each select="str:split(substring-after($args, ':'), ':')"> |
|
41 <arg> |
|
42 <xsl:attribute name="value"> |
|
43 <xsl:value-of select="."/> |
|
44 </xsl:attribute> |
|
45 </arg> |
|
46 </xsl:for-each> |
|
47 <xsl:variable name="paths" select="substring-after($description,'@')"/> |
|
48 <xsl:for-each select="str:split($paths, '@')"> |
|
49 <xsl:if test="string-length(.) > 0"> |
|
50 <path> |
|
51 <xsl:variable name="pathminmax" select="str:split(.,',')"/> |
|
52 <xsl:variable name="path" select="$pathminmax[1]"/> |
|
53 <xsl:variable name="pathminmaxcount" select="count($pathminmax)"/> |
|
54 <xsl:attribute name="value"> |
|
55 <xsl:value-of select="$path"/> |
|
56 </xsl:attribute> |
|
57 <xsl:choose> |
|
58 <xsl:when test="$pathminmaxcount = 3"> |
|
59 <xsl:attribute name="min"> |
|
60 <xsl:value-of select="$pathminmax[2]"/> |
|
61 </xsl:attribute> |
|
62 <xsl:attribute name="max"> |
|
63 <xsl:value-of select="$pathminmax[3]"/> |
|
64 </xsl:attribute> |
|
65 </xsl:when> |
|
66 <xsl:when test="$pathminmaxcount = 2"> |
|
67 <xsl:message terminate="yes"> |
|
68 <xsl:text>Widget id:</xsl:text> |
|
69 <xsl:value-of select="$id"/> |
|
70 <xsl:text> label:</xsl:text> |
|
71 <xsl:value-of select="$label"/> |
|
72 <xsl:text> has wrong syntax of path section </xsl:text> |
|
73 <xsl:value-of select="$pathminmax"/> |
|
74 </xsl:message> |
|
75 </xsl:when> |
|
76 </xsl:choose> |
|
77 <xsl:choose> |
|
78 <xsl:when test="regexp:test($path,'^\.[a-zA-Z0-9_]+$')"> |
|
79 <xsl:attribute name="type"> |
|
80 <xsl:text>PAGE_LOCAL</xsl:text> |
|
81 </xsl:attribute> |
|
82 </xsl:when> |
|
83 <xsl:when test="regexp:test($path,'^[a-zA-Z0-9_]+$')"> |
|
84 <xsl:attribute name="type"> |
|
85 <xsl:text>HMI_LOCAL</xsl:text> |
|
86 </xsl:attribute> |
|
87 </xsl:when> |
|
88 <xsl:otherwise> |
|
89 <xsl:variable name="item" select="$indexed_hmitree/*[@hmipath = $path]"/> |
|
90 <xsl:variable name="pathtype" select="local-name($item)"/> |
|
91 <xsl:if test="$pathminmaxcount = 3 and not($pathtype = 'HMI_INT' or $pathtype = 'HMI_REAL')"> |
|
92 <xsl:message terminate="yes"> |
|
93 <xsl:text>Widget id:</xsl:text> |
|
94 <xsl:value-of select="$id"/> |
|
95 <xsl:text> label:</xsl:text> |
|
96 <xsl:value-of select="$label"/> |
|
97 <xsl:text> path section </xsl:text> |
|
98 <xsl:value-of select="$pathminmax"/> |
|
99 <xsl:text> use min and max on non mumeric value</xsl:text> |
|
100 </xsl:message> |
|
101 </xsl:if> |
|
102 <xsl:if test="count($item) = 1"> |
|
103 <xsl:attribute name="index"> |
|
104 <xsl:value-of select="$item/@index"/> |
|
105 </xsl:attribute> |
|
106 <xsl:attribute name="type"> |
|
107 <xsl:value-of select="$pathtype"/> |
|
108 </xsl:attribute> |
|
109 </xsl:if> |
|
110 </xsl:otherwise> |
|
111 </xsl:choose> |
|
112 </path> |
|
113 </xsl:if> |
|
114 </xsl:for-each> |
|
115 </widget> |
|
116 </xsl:if> |
|
117 </xsl:template> |
|
118 <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="@*"> |
|
119 <xsl:copy/> |
|
120 </xsl:template> |
|
121 <xsl:template mode="inline_svg" match="node()"> |
|
122 <xsl:copy> |
|
123 <xsl:apply-templates mode="inline_svg" select="@* | node()"/> |
|
124 </xsl:copy> |
|
125 </xsl:template> |
|
126 <xsl:template match="/"> |
|
127 <xsl:comment> |
|
128 <xsl:text>Widget dropped in Inkscape from Beremiz</xsl:text> |
|
129 </xsl:comment> |
|
130 <xsl:apply-templates mode="inline_svg" select="/"/> |
|
131 </xsl:template> |
|
132 </xsl:stylesheet> |