svghmi/gen_index_xhtml.ysl2
author Edouard Tisserant
Wed, 18 Sep 2019 11:09:35 +0200
branchsvghmi
changeset 2779 75c6a31caca6
parent 2763 ce04d79b8e57
child 2780 e468f18df200
permissions -rw-r--r--
SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
include yslt_noindent.yml2

// overrides yslt's output function to set CDATA
decl output(method, cdata-section-elements="script");
istylesheet 
            /* From Inkscape */
            xmlns:dc="http://purl.org/dc/elements/1.1/"
            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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
            xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
            xmlns="http://www.w3.org/1999/xhtml"

            /* Our namespace to invoke python code */
            xmlns:ns="beremiz"
            extension-element-prefixes="ns" 
            exclude-result-prefixes="ns" {
    
    /* This retrieves geometry obtained through "inkscape -S" 
     * already parsed by python and presented as a list of 
     * <bbox x="0" y="0" w="42" h="42">
     */
    variable "geometry", "ns:GetSVGGeometry()";
    variable "hmitree", "ns:GetHMITree()";
   
    /* Identity template :
     *  - copy every attributes 
     *  - copy every sub-elements
     */
    template "@* | node()" {
      /* use real xsl:copy instead copy-of alias from yslt.yml2 */
      xsl:copy apply "@* | node()";
    }

    /* copy root node and add geometry as comment for a test */
    template "/" 
      html xmlns="http://www.w3.org/1999/xhtml" {
          head;
          body style="margin:0;" {
              xsl:copy {
                  comment {
                      apply "$geometry", mode="testgeo";
                  }
                  comment {
                      apply "$hmitree", mode="testtree";
                  }
                  apply "@* | node()";
              }
              script
                  ||
                  (function(){
                      var relative_URI = window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws');
                      var ws = new WebSocket(relative_URI);
                      ws.onmessage = function (evt) {
                          var received_msg = evt.data;
                          alert("Message is received..."+received_msg); 
                      };
                      ws.onopen = function (evt) {
                          ws.send("test");
                      };
                  })();
                  ||
          }
    }

    template "bbox", mode="testgeo"{
        | ID: «@Id» x: «@x» y: «@y» w: «@w» h: «@h»
    }

    template "*", mode="testtree"{
        param "indent", "''";
        | «$indent» «local-name()» «@name» «@type» «@path»
        apply "*", mode="testtree" {
            with "indent" value "concat($indent,'>')"
        };
    }
}