svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2793 2a97688c94c5
parent 2792 0c0d3895b036
child 2794 c10069a02ed0
equal deleted inserted replaced
2792:0c0d3895b036 2793:2a97688c94c5
    12             xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    12             xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    13             xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    13             xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    14 
    14 
    15             /* Our namespace to invoke python code */
    15             /* Our namespace to invoke python code */
    16             xmlns:ns="beremiz"
    16             xmlns:ns="beremiz"
    17             extension-element-prefixes="ns"
    17             extension-element-prefixes="ns func"
    18             exclude-result-prefixes="ns str regexp exsl" {
    18             exclude-result-prefixes="ns str regexp exsl func" {
    19 
    19 
    20     /* This retrieves geometry obtained through "inkscape -S"
    20     /* This retrieves geometry obtained through "inkscape -S"
    21      * already parsed by python and presented as a list of
    21      * already parsed by python and presented as a list of
    22      * <bbox x="0" y="0" w="42" h="42">
    22      * <bbox x="0" y="0" w="42" h="42">
    23      */
    23      */
    81 
    81 
    82     const "mark" > =HMI=\n
    82     const "mark" > =HMI=\n
    83 
    83 
    84     /* copy root node and add geometry as comment for a test */
    84     /* copy root node and add geometry as comment for a test */
    85     template "/" { 
    85     template "/" { 
       
    86         comment > Made with SVGHMI. https://beremiz.org
    86         html xmlns="http://www.w3.org/1999/xhtml" {
    87         html xmlns="http://www.w3.org/1999/xhtml" {
    87             head;
    88             head;
    88             body style="margin:0;" {
    89             body style="margin:0;" {
    89                 xsl:copy {
    90                 xsl:copy {
    90                     comment {
    91                     comment {
   101                 script{
   102                 script{
   102                     call "scripts";
   103                     call "scripts";
   103                 }
   104                 }
   104             }
   105             }
   105         }
   106         }
       
   107     }
       
   108 
       
   109     func:function name="func:parselabel" {
       
   110         param "label";
       
   111         const "description", "substring-after($label,'HMI:')";
       
   112 
       
   113         const "_args", "substring-before($description,'@')";
       
   114         const "args" choose {
       
   115             when "$_args" value "$_args";
       
   116             otherwise value "$description";
       
   117         }
       
   118 
       
   119         const "_type", "substring-before($args,':')";
       
   120         const "type" choose {
       
   121             when "$_type" value "$_type";
       
   122             otherwise value "$args";
       
   123         }
       
   124 
       
   125         const "ast" if "$type" widget {
       
   126             attrib "type" > «$type»
       
   127             foreach "str:split($args, ':')" {
       
   128                 arg {
       
   129                     attrib "value" > «.»
       
   130                 }
       
   131             }
       
   132             const "paths", "substring-after($description,'@')";
       
   133             foreach "str:split($paths, '@')" {
       
   134                 path {
       
   135                     attrib "value" > «.»
       
   136                 }
       
   137             }
       
   138         }
       
   139 
       
   140         func:result select="exsl:node-set($ast)"
   106     }
   141     }
   107 
   142 
   108     function "scripts"
   143     function "scripts"
   109     {
   144     {
   110         /* TODO : paste hmitree hash stored in hmi tree root node */
   145         /* TODO : paste hmitree hash stored in hmi tree root node */
   152         | }
   187         | }
   153         |
   188         |
   154         | var page_desc = {
   189         | var page_desc = {
   155 
   190 
   156         // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI'
   191         // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI'
   157         foreach "//*[starts-with(@inkscape:label,'HMI:')]" {
   192         foreach "//*[func:parselabel(@inkscape:label)/widget/@type = 'Page']" {
   158             | «@inkscape:label»
   193             | «@inkscape:label»
   159             const "ast" call "parse_label" with "label","@inkscape:label";
   194             const "ast", "func:parselabel(@inkscape:label)";
   160             apply "exsl:node-set($ast)", mode="testtree";
   195             apply "$ast", mode="testtree";
   161         }
   196         }
   162         | }
   197         | }
   163 
   198 
   164         include text svghmi.js
   199         include text svghmi.js
   165     }
   200     }
   174             arg value="param2";
   209             arg value="param2";
   175             path value="path1";
   210             path value="path1";
   176             path value="path2";
   211             path value="path2";
   177         }
   212         }
   178     */
   213     */
   179     function "parse_label" {
       
   180         param "label";
       
   181         const "description", "substring-after($label,'HMI:')";
       
   182 
       
   183         const "_args", "substring-before($description,'@')";
       
   184         const "args" choose {
       
   185             when "$_args" value "$_args";
       
   186             otherwise value "$description";
       
   187         }
       
   188 
       
   189         const "_type", "substring-before($args,':')";
       
   190         const "type" choose {
       
   191             when "$_type" value "$_type";
       
   192             otherwise value "$args";
       
   193         }
       
   194 
       
   195         if "$type" widget {
       
   196             attrib "type" > «$type»
       
   197             foreach "str:split($args, ':')" {
       
   198                 arg {
       
   199                     attrib "value" > «.»
       
   200                 }
       
   201             }
       
   202             const "paths", "substring-after($description,'@')";
       
   203             foreach "str:split($paths, '@')" {
       
   204                 path {
       
   205                     attrib "value" > «.»
       
   206                 }
       
   207             }
       
   208         }
       
   209     }
       
   210 
   214 
   211     template "*", mode="page_desc" {
   215     template "*", mode="page_desc" {
   212     }
   216     }
   213 
   217 
   214     template "*", mode="code_from_descs" {
   218     template "*", mode="code_from_descs" {