--- a/svghmi/gen_index_xhtml.xslt Fri Feb 14 10:29:10 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Fri Feb 14 21:41:13 2020 +0100
@@ -1,5 +1,5 @@
-<xsl:stylesheet xmlns:func="http://exslt.org/functions" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" 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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" 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">
+<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"> <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
<xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
<xsl:variable name="hmitree" select="ns:GetHMITree()"/>
@@ -118,7 +118,7 @@
<xsl:template mode="inline_svg" match="svg:svg[@viewBox!=concat('0 0 ', @width, ' ', @height)]">
<xsl:message terminate="yes">
- <xsl:text>Scale other than 1.000 in Inkscape's document properties is not supported</xsl:text>
+ <xsl:text>ViewBox settings other than X=0, Y=0 and Scale=1 are not supported</xsl:text> <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']">
@@ -200,6 +200,21 @@
<func:result select="exsl:node-set($ast)"/>
+ <func:function name="func:refered_elements"> + <xsl:param name="elems"/> + <xsl:variable name="descend" select="$elems/descendant-or-self::svg:*"/> + <xsl:variable name="clones" select="$descend[self::svg:use]"/> + <xsl:variable name="reals" select="$descend[not(self::svg:use)]"/> + <xsl:variable name="originals" select="//svg:*[concat('#',@id) = $clones/@xlink:href]"/> + <xsl:when test="$originals"> + <func:result select="$reals | func:refered_elements($originals)"/> + <func:result select="$reals"/> <xsl:template name="scripts">
@@ -312,7 +327,8 @@
<xsl:variable name="page" select="."/>
<xsl:variable name="p" select="$hmi_geometry[@Id = $page/@id]"/>
<xsl:variable name="page_ids" select="$hmi_geometry[@Id != $page/@id and @x >= $p/@x and @y >= $p/@y and @x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id"/>
- <xsl:variable name="page_elements" select="$hmi_elements[@id = $page_ids]"/>
+ <xsl:variable name="page_sub_ids" select="func:refered_elements($page)[@id = $hmi_elements/@id]/@id"/> + <xsl:variable name="all_page_ids" select="$page_ids | $page_sub_ids[not(. = $page_ids)]"/> <xsl:value-of select="$desc/arg[1]/@value"/>
@@ -333,7 +349,7 @@
- <xsl:for-each select="$page_ids">
+ <xsl:for-each select="$all_page_ids"> <xsl:text> hmi_widgets["</xsl:text>
<xsl:value-of select="."/>
@@ -1096,13 +1112,18 @@
<xsl:template mode="widget_defs" match="widget[@type='Jump']">
+ <xsl:param name="hmi_element"/> + <xsl:text>on_click: function() { + <xsl:text> switch_page(this.args[0]); <xsl:text>init: function() {
- <xsl:text> this.element.addEventListener(
- <xsl:text> evt => switch_page(this.args[0]));
+ <xsl:text> this.element.setAttribute("onclick", "hmi_widgets['</xsl:text> + <xsl:value-of select="$hmi_element/@id"/> + <xsl:text>'].on_click()"); --- a/svghmi/gen_index_xhtml.ysl2 Fri Feb 14 10:29:10 2020 +0100
+++ b/svghmi/gen_index_xhtml.ysl2 Fri Feb 14 21:41:13 2020 +0100
@@ -20,6 +20,7 @@
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"
@@ -204,6 +205,21 @@
func:result select="exsl:node-set($ast)"
+ // returns all directly or indirectly refered elements + func:function name="func:refered_elements" { + const "descend", "$elems/descendant-or-self::svg:*"; + const "clones", "$descend[self::svg:use]"; + const "reals", "$descend[not(self::svg:use)]"; + const "originals", "//svg:*[concat('#',@id) = $clones/@xlink:href]"; + func:result select="$reals | func:refered_elements($originals)"; + func:result select="$reals"; @@ -276,12 +292,13 @@
const "page_ids","""$hmi_geometry[@Id != $page/@id and
@x >= $p/@x and @y >= $p/@y and
@x+@w <= $p/@x+$p/@w and @y+@h <= $p/@y+$p/@h]/@Id""";
- const "page_elements", "$hmi_elements[@id = $page_ids]";
+ const "page_sub_ids", "func:refered_elements($page)[@id = $hmi_elements/@id]/@id"; + const "all_page_ids","$page_ids | $page_sub_ids[not(. = $page_ids)]"; | "«$desc/arg[1]/@value»": {
| bbox: [«$p/@x», «$p/@y», «$p/@w», «$p/@h»],
+ foreach "$all_page_ids" { | hmi_widgets["«.»"]`if "position()!=last()" > ,`
@@ -455,10 +472,17 @@
template "widget[@type='Jump']", mode="widget_defs" {
+ | on_click: function() { + | switch_page(this.args[0]); - | this.element.addEventListener(
- | evt => switch_page(this.args[0]));
+ /* registering event this way doies not "click" through svg:use + | this.element.onclick = evt => switch_page(this.args[0]); + event must be registered by adding attribute to element instead + TODO : generalize mouse event handling by global event capture + getElementsAtPoint() + | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click()");