svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2854 c7d5f46cc306
parent 2852 f7349ca820c9
child 2856 1b529ba018ad
equal deleted inserted replaced
2853:6d39beb19f38 2854:c7d5f46cc306
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet xmlns:func="http://exslt.org/functions" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg" xmlns:str="http://exslt.org/strings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exsl="http://exslt.org/common" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns func" version="1.0" exclude-result-prefixes="ns str regexp exsl func">
     2 <xsl:stylesheet xmlns:func="http://exslt.org/functions" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg" xmlns:str="http://exslt.org/strings" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exsl="http://exslt.org/common" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0" exclude-result-prefixes="ns str regexp exsl func dyn">
     3   <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
     3   <xsl:output method="xml" cdata-section-elements="xhtml: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="svg_root_id" select="/svg:svg/@id"/>
     6   <xsl:variable name="svg_root_id" select="/svg:svg/@id"/>
     7   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     7   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
    98       <xsl:otherwise>
    98       <xsl:otherwise>
    99         <func:result select="0"/>
    99         <func:result select="0"/>
   100       </xsl:otherwise>
   100       </xsl:otherwise>
   101     </xsl:choose>
   101     </xsl:choose>
   102   </func:function>
   102   </func:function>
   103   <xsl:variable name="groups" select="/svg:svg | //svg:g"/>
       
   104   <func:function name="func:overlapping_geometry">
   103   <func:function name="func:overlapping_geometry">
   105     <xsl:param name="elt"/>
   104     <xsl:param name="elt"/>
       
   105     <xsl:variable name="groups" select="/svg:svg | //svg:g"/>
   106     <xsl:variable name="g" select="$geometry[@Id = $elt/@id]"/>
   106     <xsl:variable name="g" select="$geometry[@Id = $elt/@id]"/>
   107     <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
   107     <xsl:variable name="candidates" select="$geometry[@Id != $elt/@id]"/>
   108     <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or &#10;                              (not(@Id = $groups/@id) and (func:intersect($g, .) &gt; 0 ))]"/>
   108     <func:result select="$candidates[(@Id = $groups/@id and (func:intersect($g, .) = 9)) or &#10;                              (not(@Id = $groups/@id) and (func:intersect($g, .) &gt; 0 ))]"/>
   109   </func:function>
   109   </func:function>
   110   <func:function name="func:all_related_elements">
   110   <func:function name="func:all_related_elements">
   128   <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:*&#10;           | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/>
   128   <xsl:variable name="required_elements" select="//svg:defs/descendant-or-self::svg:*&#10;           | func:required_elements($hmi_pages)/ancestor-or-self::svg:*"/>
   129   <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/>
   129   <xsl:variable name="discardable_elements" select="//svg:*[not(@id = $required_elements/@id)]"/>
   130   <func:function name="func:sumarized_elements">
   130   <func:function name="func:sumarized_elements">
   131     <xsl:param name="elements"/>
   131     <xsl:param name="elements"/>
   132     <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/>
   132     <xsl:variable name="short_list" select="$elements[not(ancestor::*/@id = $elements/@id)]"/>
   133     <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[&#10;            not(descendant::*[&#10;                not(self::svg:g) and &#10;                not(@id = $discardable_elements/@id) and&#10;                not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)&#10;            ])]"/>
   133     <xsl:variable name="filled_groups" select="$short_list/parent::svg:*[&#10;            not(descendant::*[&#10;                not(self::svg:g) and&#10;                not(@id = $discardable_elements/@id) and&#10;                not(@id = $short_list/descendant-or-self::*[not(self::svg:g)]/@id)&#10;            ])]"/>
   134     <xsl:variable name="groups_to_add" select="$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"/>
   134     <xsl:variable name="groups_to_add" select="$filled_groups[not(ancestor::*/@id = $filled_groups/@id)]"/>
   135     <func:result select="$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]"/>
   135     <func:result select="$groups_to_add | $short_list[not(ancestor::svg:g/@id = $filled_groups/@id)]"/>
   136   </func:function>
   136   </func:function>
   137   <func:function name="func:detachable_elements">
   137   <func:function name="func:detachable_elements">
   138     <xsl:param name="pages"/>
   138     <xsl:param name="pages"/>
   225   <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']">
   225   <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']">
   226     <xsl:message terminate="yes">
   226     <xsl:message terminate="yes">
   227       <xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text>
   227       <xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text>
   228     </xsl:message>
   228     </xsl:message>
   229   </xsl:template>
   229   </xsl:template>
       
   230   <xsl:variable name="to_unlink" select="$hmi_elements[not(@id = $hmi_pages)]//svg:use"/>
       
   231   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:use">
       
   232     <xsl:choose>
       
   233       <xsl:when test="@id = $to_unlink/@id">
       
   234         <xsl:call-template name="unlink_clone"/>
       
   235       </xsl:when>
       
   236       <xsl:otherwise>
       
   237         <xsl:copy>
       
   238           <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
       
   239         </xsl:copy>
       
   240       </xsl:otherwise>
       
   241     </xsl:choose>
       
   242   </xsl:template>
       
   243   <xsl:variable name="_excluded_use_attrs">
       
   244     <name>
       
   245       <xsl:text>href</xsl:text>
       
   246     </name>
       
   247     <name>
       
   248       <xsl:text>width</xsl:text>
       
   249     </name>
       
   250     <name>
       
   251       <xsl:text>height</xsl:text>
       
   252     </name>
       
   253     <name>
       
   254       <xsl:text>x</xsl:text>
       
   255     </name>
       
   256     <name>
       
   257       <xsl:text>y</xsl:text>
       
   258     </name>
       
   259   </xsl:variable>
       
   260   <xsl:variable name="excluded_use_attrs" select="exsl:node-set($_excluded_use_attrs)"/>
       
   261   <xsl:template xmlns="http://www.w3.org/2000/svg" name="unlink_clone">
       
   262     <g>
       
   263       <xsl:for-each select="@*[not(local-name() = $excluded_use_attrs/name)]">
       
   264         <xsl:attribute name="{name()}">
       
   265           <xsl:value-of select="."/>
       
   266         </xsl:attribute>
       
   267       </xsl:for-each>
       
   268       <xsl:variable name="targetid" select="substring-after(@xlink:href,'#')"/>
       
   269       <xsl:apply-templates mode="unlink_clone" select="//svg:*[@id = $targetid]">
       
   270         <xsl:with-param name="seed" select="@id"/>
       
   271       </xsl:apply-templates>
       
   272     </g>
       
   273   </xsl:template>
       
   274   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="@id">
       
   275     <xsl:param name="seed"/>
       
   276     <xsl:attribute name="id">
       
   277       <xsl:value-of select="$seed"/>
       
   278       <xsl:text>_</xsl:text>
       
   279       <xsl:value-of select="."/>
       
   280     </xsl:attribute>
       
   281   </xsl:template>
       
   282   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="@*">
       
   283     <xsl:copy/>
       
   284   </xsl:template>
       
   285   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="unlink_clone" match="svg:*">
       
   286     <xsl:param name="seed"/>
       
   287     <xsl:choose>
       
   288       <xsl:when test="@id = $hmi_elements/@id">
       
   289         <use>
       
   290           <xsl:attribute name="xlink:href">
       
   291             <xsl:value-of select="concat('#',@id)"/>
       
   292           </xsl:attribute>
       
   293         </use>
       
   294       </xsl:when>
       
   295       <xsl:otherwise>
       
   296         <xsl:copy>
       
   297           <xsl:apply-templates mode="unlink_clone" select="@* | node()">
       
   298             <xsl:with-param name="seed" select="$seed"/>
       
   299           </xsl:apply-templates>
       
   300         </xsl:copy>
       
   301       </xsl:otherwise>
       
   302     </xsl:choose>
       
   303   </xsl:template>
       
   304   <xsl:variable name="result_svg">
       
   305     <xsl:apply-templates mode="inline_svg" select="/"/>
       
   306   </xsl:variable>
       
   307   <xsl:variable name="result_svg_ns" select="exsl:node-set($result_svg)"/>
   230   <xsl:template match="/">
   308   <xsl:template match="/">
   231     <xsl:comment>
   309     <xsl:comment>
   232       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
   310       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
   233     </xsl:comment>
   311     </xsl:comment>
   234     <xsl:comment>
   312     <xsl:comment>
   256         <xsl:value-of select="@id"/>
   334         <xsl:value-of select="@id"/>
   257         <xsl:text>
   335         <xsl:text>
   258 </xsl:text>
   336 </xsl:text>
   259       </xsl:for-each>
   337       </xsl:for-each>
   260     </xsl:comment>
   338     </xsl:comment>
       
   339     <xsl:comment>
       
   340       <xsl:text>Unlinked :
       
   341 </xsl:text>
       
   342       <xsl:for-each select="$to_unlink">
       
   343         <xsl:value-of select="@id"/>
       
   344         <xsl:text>
       
   345 </xsl:text>
       
   346       </xsl:for-each>
       
   347     </xsl:comment>
   261     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
   348     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
   262       <head/>
   349       <head/>
   263       <body style="margin:0;overflow:hidden;">
   350       <body style="margin:0;overflow:hidden;">
   264         <xsl:variable name="_result_svg">
   351         <xsl:copy-of select="$result_svg"/>
   265           <xsl:apply-templates mode="inline_svg" select="svg:svg"/>
       
   266         </xsl:variable>
       
   267         <xsl:copy-of select="$_result_svg"/>
       
   268         <xsl:variable name="result_svg" select="exsl:node-set($_result_svg)"/>
       
   269         <script>
   352         <script>
   270           <xsl:apply-templates mode="scripts" select="svg:svg"/>
   353           <xsl:call-template name="scripts"/>
   271         </script>
   354         </script>
   272       </body>
   355       </body>
   273     </html>
   356     </html>
   274   </xsl:template>
   357   </xsl:template>
   275   <func:function name="func:parselabel">
   358   <func:function name="func:parselabel">
   321         </widget>
   404         </widget>
   322       </xsl:if>
   405       </xsl:if>
   323     </xsl:variable>
   406     </xsl:variable>
   324     <func:result select="exsl:node-set($ast)"/>
   407     <func:result select="exsl:node-set($ast)"/>
   325   </func:function>
   408   </func:function>
   326   <xsl:template mode="scripts" match="svg:svg">
   409   <xsl:template name="scripts">
   327     <xsl:text>//(function(){
   410     <xsl:text>//(function(){
   328 </xsl:text>
   411 </xsl:text>
   329     <xsl:text>
   412     <xsl:text>
   330 </xsl:text>
   413 </xsl:text>
   331     <xsl:text>id = idstr =&gt; document.getElementById(idstr);
   414     <xsl:text>id = idstr =&gt; document.getElementById(idstr);
   384             <xsl:text>
   467             <xsl:text>
   385 </xsl:text>
   468 </xsl:text>
   386           </xsl:otherwise>
   469           </xsl:otherwise>
   387         </xsl:choose>
   470         </xsl:choose>
   388       </xsl:for-each>
   471       </xsl:for-each>
   389       <xsl:text>        ],
   472       <xsl:text>    ],
   390 </xsl:text>
   473 </xsl:text>
   391       <xsl:text>        element: id("</xsl:text>
   474       <xsl:text>    element: id("</xsl:text>
   392       <xsl:value-of select="@id"/>
   475       <xsl:value-of select="@id"/>
   393       <xsl:text>"),
   476       <xsl:text>"),
   394 </xsl:text>
   477 </xsl:text>
   395       <xsl:apply-templates mode="widget_defs" select="$widget">
   478       <xsl:apply-templates mode="widget_defs" select="$widget">
   396         <xsl:with-param name="hmi_element" select="."/>
   479         <xsl:with-param name="hmi_element" select="."/>
   397       </xsl:apply-templates>
   480       </xsl:apply-templates>
   398       <xsl:text>    }</xsl:text>
   481       <xsl:text>  }</xsl:text>
   399       <xsl:if test="position()!=last()">
   482       <xsl:if test="position()!=last()">
   400         <xsl:text>,</xsl:text>
   483         <xsl:text>,</xsl:text>
   401       </xsl:if>
   484       </xsl:if>
   402       <xsl:text>
   485       <xsl:text>
   403 </xsl:text>
   486 </xsl:text>
  1140   <xsl:template mode="testtree" match="*">
  1223   <xsl:template mode="testtree" match="*">
  1141     <xsl:param name="indent" select="''"/>
  1224     <xsl:param name="indent" select="''"/>
  1142     <xsl:value-of select="$indent"/>
  1225     <xsl:value-of select="$indent"/>
  1143     <xsl:text> </xsl:text>
  1226     <xsl:text> </xsl:text>
  1144     <xsl:value-of select="local-name()"/>
  1227     <xsl:value-of select="local-name()"/>
  1145     <xsl:text> </xsl:text>
       
  1146     <xsl:for-each select="@*">
  1228     <xsl:for-each select="@*">
  1147       <xsl:value-of select="local-name()"/>
  1229       <xsl:value-of select="local-name()"/>
  1148       <xsl:text>=</xsl:text>
  1230       <xsl:text>=</xsl:text>
  1149       <xsl:value-of select="."/>
  1231       <xsl:value-of select="."/>
  1150       <xsl:text> </xsl:text>
       
  1151     </xsl:for-each>
  1232     </xsl:for-each>
  1152     <xsl:text>
  1233     <xsl:text>
  1153 </xsl:text>
  1234 </xsl:text>
  1154     <xsl:apply-templates mode="testtree" select="*">
  1235     <xsl:apply-templates mode="testtree" select="*">
  1155       <xsl:with-param name="indent">
  1236       <xsl:with-param name="indent">
  1162     <xsl:param name="mandatory" select="'yes'"/>
  1243     <xsl:param name="mandatory" select="'yes'"/>
  1163     <xsl:param name="hmi_element"/>
  1244     <xsl:param name="hmi_element"/>
  1164     <xsl:variable name="widget_type" select="@type"/>
  1245     <xsl:variable name="widget_type" select="@type"/>
  1165     <xsl:for-each select="str:split($labels)">
  1246     <xsl:for-each select="str:split($labels)">
  1166       <xsl:variable name="name" select="."/>
  1247       <xsl:variable name="name" select="."/>
  1167       <xsl:variable name="elt_id" select="$hmi_element//*[@inkscape:label=$name][1]/@id"/>
  1248       <xsl:variable name="elt_id" select="$result_svg_ns//*[@id = $hmi_element/@id]//*[@inkscape:label=$name][1]/@id"/>
  1168       <xsl:choose>
  1249       <xsl:choose>
  1169         <xsl:when test="not($elt_id)">
  1250         <xsl:when test="not($elt_id)">
  1170           <xsl:if test="$mandatory='yes'">
  1251           <xsl:if test="$mandatory='yes'">
  1171             <xsl:message terminate="no">
  1252             <xsl:message terminate="no">
  1172               <xsl:value-of select="$widget_type"/>
  1253               <xsl:value-of select="$widget_type"/>