This is an Open Web Archive archive of https://gitlab.dyomedea.com/presentations/xmlamsterdam2013/blob/master/events.xsl.
This snapshot has been taken on 2014-01-08 21:24:44 for the website Eric van der Vlist which contains a link to this page and has saved a copy to be displayed in the page ever disappears.
presentations / XML Amsterdam 2013 | GitLab
events.xsl 5.05 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © 2013 Eric van der Vlist <vdv@dyomedea.com>
See license information at the bottom of this file
-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:d="http://dyomedea.com"
xmlns:js="http://saxonica.com/ns/globalJS" xmlns:ixsl="http://saxonica.com/ns/interactiveXSLT"
extension-element-prefixes="ixsl">

<xsl:import href="serialization.xsl"/>
<xsl:include href="saxon-ce-dummy-declarations.xsl"/>

<xsl:function name="d:apply-update-transformation">
<xsl:param name="transformation-uri" as="xs:anyURI"/>
<xsl:param name="instance"/>
<xsl:param name="init-template" as="xs:string"/>
<xsl:variable name="transformation" select="js:Saxon.requestXML($transformation-uri)"/>
<!-- Apply the transformation -->
<xsl:variable name="xsltProcessor" select="js:Saxon.newXSLT20Processor($transformation)"/>
<ixsl:set-property name="dummy"
select="ixsl:call($xsltProcessor, 'setInitialTemplate', $init-template)"/>
<ixsl:set-property name="dummy"
select="ixsl:call($xsltProcessor, 'updateHTMLDocument', (), $instance)"/>
<ixsl:set-property name="xsltProcessor" select="$xsltProcessor"/>

<!-- Keep a copy for the introspection -->
<ixsl:set-property name="otherXML"
select="(ixsl:get(ixsl:window(), 'otherXML'), string($transformation-uri))"/>

<xsl:sequence select="$xsltProcessor"/>


</xsl:function>

<xsl:function name="d:new-custom-event">
<xsl:param name="name" as="xs:string"/>
<xsl:variable name="js-statement" as="element()">
<root statement="new CustomEvent ( '{$name}',{{ detail: {{}} }})"/>
</xsl:variable>
<xsl:sequence select="ixsl:eval(string($js-statement/@statement))"/>
</xsl:function>

<xsl:function name="d:new-event">
<xsl:param name="name" as="xs:string"/>
<xsl:variable name="event" select="ixsl:call(ixsl:page(), 'createEvent', 'HTMLEvents')"/>
<ixsl:set-property name="dummy" select="ixsl:call($event, 'initEvent', $name, true(), true())"/>
<xsl:sequence select="$event"/>
</xsl:function>

<xsl:function name="d:dispatch-event-to-instance">
<xsl:param name="target"/>
<xsl:param name="event"/>
<ixsl:set-property object="$event" name="detail.target" select="$target"/>
<ixsl:set-property name="dummy" select="ixsl:call(ixsl:window(), 'onEventWorkaround', $event)"/>
</xsl:function>

<xsl:function name="d:dispatch-event">
<xsl:param name="target"/>
<xsl:param name="event"/>
<ixsl:set-property name="dummy" select="ixsl:call($target, 'dispatchEvent', $event)"/>
</xsl:function>


<xsl:function name="d:path" as="xs:string">
<xsl:param name="node"/>
<xsl:choose>
<xsl:when test="$node instance of document-node()">
<xsl:sequence select="''"/>
</xsl:when>
<xsl:when test="$node instance of attribute()">
<xsl:sequence select="concat(d:path($node/..), '/@', name($node))"/>
</xsl:when>
<xsl:when test="$node instance of element()">
<xsl:sequence
select="concat(d:path($node/..), '/', name($node), '[', count($node/preceding-sibling::*[local-name(.)=local-name($node) and namespace-uri(.) = namespace-uri($node)]) + 1, ']')"
/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="d:path($node/..)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>

<xsl:template match="ixsl:window()" mode="ixsl:onEventWorkaround">
<xsl:message>Got en event</xsl:message>
<xsl:variable name="event" select="ixsl:event()"/>
<xsl:choose>
<xsl:when test="ixsl:get($event, 'type') = 'ModelUpdate'">
<!--<xsl:apply-templates select="ixsl:get(event, 'detail.target')" mode="d:onModelUpdate">-->
<xsl:apply-templates
select="ixsl:get(ixsl:window(), 'instance')//*[d:path(.) = d:path(ixsl:get($event, 'detail.target'))]"
mode="d:onModelUpdate">
<xsl:with-param name="event" select="$event"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
<!--
Copyright © 2013 Eric van der Vlist <vdv@dyomedea.com>
This file is part of
<https://gitlab.dyomedea.com/public/projects/presentations/xmlamsterdam2013>.
This sotfware is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This sotfware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
-->