svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2790 8fab1886ebec
parent 2789 ba0dd2ec6dc4
child 2791 d022523cb621
equal deleted inserted replaced
2789:ba0dd2ec6dc4 2790:8fab1886ebec
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/1999/xhtml" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns" extension-element-prefixes="ns" version="1.0">
     2 <xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns" extension-element-prefixes="ns" version="1.0">
     3   <xsl:output method="xml" cdata-section-elements="script"/>
     3   <xsl:output method="xml" cdata-section-elements="script"/>
     4   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
     4   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
     5   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
     5   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
       
     6   <xsl:variable name="_categories">
       
     7     <noindex>
       
     8       <xsl:text>HMI_ROOT</xsl:text>
       
     9     </noindex>
       
    10     <noindex>
       
    11       <xsl:text>HMI_LABEL</xsl:text>
       
    12     </noindex>
       
    13     <noindex>
       
    14       <xsl:text>HMI_CLASS</xsl:text>
       
    15     </noindex>
       
    16     <noindex>
       
    17       <xsl:text>HMI_PLC_STATUS</xsl:text>
       
    18     </noindex>
       
    19     <noindex>
       
    20       <xsl:text>HMI_CURRENT_PAGE</xsl:text>
       
    21     </noindex>
       
    22   </xsl:variable>
       
    23   <xsl:variable name="categories" select="exsl:node-set($_categories)"/>
       
    24   <xsl:variable name="indexed_hmitree">
       
    25     <xsl:apply-templates mode="index" select="$hmitree"/>
       
    26   </xsl:variable>
       
    27   <xsl:template mode="index" match="node()">
       
    28     <xsl:param name="index" select="0"/>
       
    29     <xsl:variable name="content">
       
    30       <xsl:choose>
       
    31         <xsl:when test="not(local-name() = $categories/noindex)">
       
    32           <xsl:copy>
       
    33             <xsl:attribute name="index">
       
    34               <xsl:value-of select="$index"/>
       
    35             </xsl:attribute>
       
    36             <xsl:for-each select="@*">
       
    37               <xsl:copy/>
       
    38             </xsl:for-each>
       
    39           </xsl:copy>
       
    40         </xsl:when>
       
    41         <xsl:otherwise>
       
    42           <xsl:apply-templates mode="index" select="*[1]">
       
    43             <xsl:with-param name="index" select="$index"/>
       
    44           </xsl:apply-templates>
       
    45         </xsl:otherwise>
       
    46       </xsl:choose>
       
    47     </xsl:variable>
       
    48     <xsl:copy-of select="$content"/>
       
    49     <xsl:apply-templates mode="index" select="following-sibling::*[1]">
       
    50       <xsl:with-param name="index" select="$index + count(exsl:node-set($content)/*)"/>
       
    51     </xsl:apply-templates>
       
    52   </xsl:template>
     6   <xsl:template match="@* | node()">
    53   <xsl:template match="@* | node()">
     7     <xsl:copy>
    54     <xsl:copy>
     8       <xsl:apply-templates select="@* | node()"/>
    55       <xsl:apply-templates select="@* | node()"/>
     9     </xsl:copy>
    56     </xsl:copy>
    10   </xsl:template>
    57   </xsl:template>
    21             <xsl:apply-templates mode="testgeo" select="$geometry"/>
    68             <xsl:apply-templates mode="testgeo" select="$geometry"/>
    22           </xsl:comment>
    69           </xsl:comment>
    23           <xsl:comment>
    70           <xsl:comment>
    24             <xsl:apply-templates mode="testtree" select="$hmitree"/>
    71             <xsl:apply-templates mode="testtree" select="$hmitree"/>
    25           </xsl:comment>
    72           </xsl:comment>
       
    73           <xsl:comment>
       
    74             <xsl:apply-templates mode="testtree" select="exsl:node-set($indexed_hmitree)"/>
       
    75           </xsl:comment>
    26           <xsl:apply-templates select="@* | node()"/>
    76           <xsl:apply-templates select="@* | node()"/>
    27         </xsl:copy>
    77         </xsl:copy>
    28         <script>
    78         <script>
    29           <xsl:text>function evaluate_js_from_descriptions() {
    79           <xsl:text>var subscriptions = {
    30 </xsl:text>
    80 </xsl:text>
    31           <xsl:text>    var Page;
       
    32 </xsl:text>
       
    33           <xsl:text>    var Input;
       
    34 </xsl:text>
       
    35           <xsl:text>    var Display;
       
    36 </xsl:text>
       
    37           <xsl:text>    var res = [];
       
    38 </xsl:text>
       
    39           <xsl:variable name="midmark">
       
    40             <xsl:text>
       
    41 </xsl:text>
       
    42             <xsl:value-of select="$mark"/>
       
    43           </xsl:variable>
       
    44           <xsl:apply-templates mode="code_from_descs" select="//*[contains(child::svg:desc, $midmark) or                                starts-with(child::svg:desc, $mark)]"/>
       
    45           <xsl:text>    return res;
    81           <xsl:text>    return res;
    46 </xsl:text>
    82 </xsl:text>
    47           <xsl:text>}
    83           <xsl:text>}
    48 </xsl:text>
    84 </xsl:text>
    49           <xsl:text>// svghmi.js
    85           <xsl:text>// svghmi.js
    93           <xsl:text>        // TODO : prefix with hmitree hash header
   129           <xsl:text>        // TODO : prefix with hmitree hash header
    94 </xsl:text>
   130 </xsl:text>
    95           <xsl:text>        ws.send("test");
   131           <xsl:text>        ws.send("test");
    96 </xsl:text>
   132 </xsl:text>
    97           <xsl:text>    };
   133           <xsl:text>    };
       
   134 </xsl:text>
       
   135           <xsl:text>
       
   136 </xsl:text>
       
   137           <xsl:text>    var pending_updates = {};
       
   138 </xsl:text>
       
   139           <xsl:text>    
       
   140 </xsl:text>
       
   141           <xsl:text>    // subscription state, as it should be in hmi server
       
   142 </xsl:text>
       
   143           <xsl:text>    // expected {index:period}
       
   144 </xsl:text>
       
   145           <xsl:text>    var subscriptions = {};
       
   146 </xsl:text>
       
   147           <xsl:text>
       
   148 </xsl:text>
       
   149           <xsl:text>
       
   150 </xsl:text>
       
   151           <xsl:text>    // subscription state as needed by widget now
       
   152 </xsl:text>
       
   153           <xsl:text>    // expected {index:[widgets]};
       
   154 </xsl:text>
       
   155           <xsl:text>    var subscribers = {};
       
   156 </xsl:text>
       
   157           <xsl:text>
       
   158 </xsl:text>
       
   159           <xsl:text>    // return the diff in between curently subscribed and subscription
       
   160 </xsl:text>
       
   161           <xsl:text>    function update_subscriptions() {
       
   162 </xsl:text>
       
   163           <xsl:text>        let result = [];
       
   164 </xsl:text>
       
   165           <xsl:text>        Object.keys(subscribers).forEach(index =&gt; {
       
   166 </xsl:text>
       
   167           <xsl:text>
       
   168 </xsl:text>
       
   169           <xsl:text>            let previous_period = subscriptions[index];
       
   170 </xsl:text>
       
   171           <xsl:text>            let new_period = Math.min(...widgets.map(widget =&gt; widget.period));
       
   172 </xsl:text>
       
   173           <xsl:text>
       
   174 </xsl:text>
       
   175           <xsl:text>            if(previous_period != new_period) 
       
   176 </xsl:text>
       
   177           <xsl:text>                result.push({index: index, period: new_period});
       
   178 </xsl:text>
       
   179           <xsl:text>        })
       
   180 </xsl:text>
       
   181           <xsl:text>    }
       
   182 </xsl:text>
       
   183           <xsl:text>
       
   184 </xsl:text>
       
   185           <xsl:text>
       
   186 </xsl:text>
       
   187           <xsl:text>    function update_value(index, value) {
       
   188 </xsl:text>
       
   189           <xsl:text>
       
   190 </xsl:text>
       
   191           <xsl:text>    };
       
   192 </xsl:text>
       
   193           <xsl:text>
    98 </xsl:text>
   194 </xsl:text>
    99           <xsl:text>})();
   195           <xsl:text>})();
   100 </xsl:text>
   196 </xsl:text>
   101         </script>
   197         </script>
   102       </body>
   198       </body>
   157     <xsl:param name="indent" select="''"/>
   253     <xsl:param name="indent" select="''"/>
   158     <xsl:value-of select="$indent"/>
   254     <xsl:value-of select="$indent"/>
   159     <xsl:text> </xsl:text>
   255     <xsl:text> </xsl:text>
   160     <xsl:value-of select="local-name()"/>
   256     <xsl:value-of select="local-name()"/>
   161     <xsl:text> </xsl:text>
   257     <xsl:text> </xsl:text>
   162     <xsl:value-of select="@name"/>
   258     <xsl:for-each select="@*">
   163     <xsl:text> </xsl:text>
   259       <xsl:value-of select="local-name()"/>
   164     <xsl:value-of select="@type"/>
   260       <xsl:text>=</xsl:text>
   165     <xsl:text> </xsl:text>
   261       <xsl:value-of select="."/>
   166     <xsl:value-of select="@path"/>
   262       <xsl:text> </xsl:text>
       
   263     </xsl:for-each>
   167     <xsl:text>
   264     <xsl:text>
   168 </xsl:text>
   265 </xsl:text>
   169     <xsl:apply-templates mode="testtree" select="*">
   266     <xsl:apply-templates mode="testtree" select="*">
   170       <xsl:with-param name="indent">
   267       <xsl:with-param name="indent">
   171         <xsl:value-of select="concat($indent,'&gt;')"/>
   268         <xsl:value-of select="concat($indent,'&gt;')"/>