svghmi/gen_index_xhtml.ysl2
branchsvghmi
changeset 2792 0c0d3895b036
parent 2791 d022523cb621
child 2793 2a97688c94c5
equal deleted inserted replaced
2791:d022523cb621 2792:0c0d3895b036
     1 include yslt_noindent.yml2
     1 include yslt_noindent.yml2
     2 
     2 
     3 // overrides yslt's output function to set CDATA
     3 // overrides yslt's output function to set CDATA
     4 decl output(method, cdata-section-elements="script");
     4 decl output(method, cdata-section-elements="script");
     5 istylesheet 
     5 
       
     6 istylesheet
     6             /* From Inkscape */
     7             /* From Inkscape */
     7             xmlns:dc="http://purl.org/dc/elements/1.1/"
     8             xmlns:dc="http://purl.org/dc/elements/1.1/"
     8             xmlns:cc="http://creativecommons.org/ns#"
     9             xmlns:cc="http://creativecommons.org/ns#"
     9             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    10             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    10             xmlns:svg="http://www.w3.org/2000/svg"
    11             xmlns:svg="http://www.w3.org/2000/svg"
    11             xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    12             xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
    12             xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    13             xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
    13             xmlns:xhtml="http://www.w3.org/1999/xhtml"
       
    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"
    18             exclude-result-prefixes="ns" {
    18             exclude-result-prefixes="ns str regexp exsl" {
    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      */
    24     const "geometry", "ns:GetSVGGeometry()";
    24     const "geometry", "ns:GetSVGGeometry()";
    25     const "hmitree", "ns:GetHMITree()";
    25     const "hmitree", "ns:GetHMITree()";
    26 
    26 
    80     }
    80     }
    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       html xmlns="http://www.w3.org/1999/xhtml" {
    86         html xmlns="http://www.w3.org/1999/xhtml" {
    87           head;
    87             head;
    88           body style="margin:0;" {
    88             body style="margin:0;" {
    89               xsl:copy {
    89                 xsl:copy {
    90                   comment {
    90                     comment {
    91                       apply "$geometry", mode="testgeo";
    91                         apply "$geometry", mode="testgeo";
    92                   }
    92                     }
    93                   comment {
    93                     comment {
    94                       apply "$hmitree", mode="testtree";
    94                         apply "$hmitree", mode="testtree";
    95                   }
    95                     }
    96                   comment {
    96                     comment {
    97                       apply "$indexed_hmitree", mode="testtree";
    97                         apply "$indexed_hmitree", mode="testtree";
    98                   }
    98                     }
    99                   apply "@* | node()", mode="identity_svg";
    99                     apply "@* | node()", mode="identity_svg";
   100               }
   100                 }
   101               script{
   101                 script{
   102                   /* TODO : paste hmitree hash stored in hmi tree root node */
   102                     call "scripts";
   103 
   103                 }
   104                   /* TODO re-enable
   104             }
   105                   ||
   105         }
   106                   function evaluate_js_from_descriptions() {
   106     }
   107                       var Page;
   107 
   108                       var Input;
   108     function "scripts"
   109                       var Display;
   109     {
   110                       var res = [];
   110         /* TODO : paste hmitree hash stored in hmi tree root node */
   111                   ||
   111 
   112                   const "midmark" > \n«$mark»
   112         /* TODO re-enable
   113                   apply """//*[contains(child::svg:desc, $midmark) or \
   113         ||
   114                                starts-with(child::svg:desc, $mark)]""",2 
   114         function evaluate_js_from_descriptions() {
   115                         mode="code_from_descs";
   115             var Page;
   116                   ||
   116             var Input;
   117                       return res;
   117             var Display;
   118                   }
   118             var res = [];
   119                   ||
   119         ||
   120                   */
   120         const "midmark" > \n«$mark»
   121 
   121         apply """//*[contains(child::svg:desc, $midmark) or \
   122                   /*TODO add :
   122                      starts-with(child::svg:desc, $mark)]""",2 
   123                     - pages content
   123               mode="code_from_descs";
   124                       + with ref to elt ?
   124         ||
   125                     - widgets parameters
   125             return res;
   126                   */
   126         }
   127 
   127         ||
   128                   | var subscriptions = {
   128         */
   129 
   129 
   130                   const "svg","/"; /* foreach loses document root */
   130         /*TODO add :
   131                   foreach "$indexed_hmitree/*" {
   131           - pages content
   132                       | «@index»: {
   132             + with ref to elt ?
   133                       |     name: "«@name»",
   133           - widgets parameters
   134                       |     hmipath: "«@hmipath»"
   134         */
   135                       |     ids: [
   135 
   136                       const "hmipath","@hmipath";
   136         | var hmi_index = {
   137                       foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" {
   137 
   138                       |         "«@id»"`if "position()!=last()" > ,`
   138         const "svg","/"; /* foreach loses document root */
   139                       }
   139         foreach "$indexed_hmitree/*" {
   140                       |     ]
   140             | «@index»: {
   141                       | }`if "position()!=last()" > ,`
   141             |     name: "«@name»",
   142                   }
   142             |     hmipath: "«@hmipath»"
   143 
   143             |     ids: [
   144                   | }
   144             const "hmipath","@hmipath";
   145 
   145             foreach "$svg//*[substring-after(@inkscape:label,'@') = $hmipath]" {
   146                   include text svghmi.js
   146             |         "«@id»"`if "position()!=last()" > ,`
   147               }
   147             }
   148           }
   148             |     ]
       
   149             | }`if "position()!=last()" > ,`
       
   150         }
       
   151 
       
   152         | }
       
   153         |
       
   154         | var page_desc = {
       
   155 
       
   156         // apply "//*[substring-after(substring-before(@inkscape:label, '@'), 'HMI'
       
   157         foreach "//*[starts-with(@inkscape:label,'HMI:')]" {
       
   158             | «@inkscape:label»
       
   159             const "ast" call "parse_label" with "label","@inkscape:label";
       
   160             apply "exsl:node-set($ast)", mode="testtree";
       
   161         }
       
   162         | }
       
   163 
       
   164         include text svghmi.js
       
   165     }
       
   166 
       
   167     /*
       
   168         Parses:
       
   169         "HMI:WidgetType:param1:param2@path1@path2"
       
   170 
       
   171         Into:
       
   172         widget type="WidgetType" {
       
   173             arg value="param1";
       
   174             arg value="param2";
       
   175             path value="path1";
       
   176             path value="path2";
       
   177         }
       
   178     */
       
   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 
       
   211     template "*", mode="page_desc" {
   149     }
   212     }
   150 
   213 
   151     template "*", mode="code_from_descs" {
   214     template "*", mode="code_from_descs" {
   152         ||
   215         ||
   153         {
   216         {