AlainCouthures / xsltforms

XForms to XHTML+Javascript (AJAX) conversion based on a unique XSL transformation. Suitable server-side (PHP) or client-side (Google Chrome, Edge, Internet Explorer, Mozilla FireFox, Opera, Safari) browser treatment where an XSLT 1.0 engine is available
37 stars 17 forks source link

In-scope evaluation context for `xf:dispatch/xf:name/@value` #27

Open HeikoTheissen opened 2 months ago

HeikoTheissen commented 2 months ago

See https://stackoverflow.com/questions/78860549

The XPath expression name(context()) appears twice in the following example, and XSLTForms evaluates both occurrences differently when the trigger is pressed:

I would have expected that the context is the same (the "in-scope evaluation context") in both cases.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="xsltforms.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xf="http://www.w3.org/2002/xforms"
  xmlns:ev="http://www.w3.org/2001/xml-events">
  <head>
    <xf:model id="model">
      <xf:instance>
        <data xmlns="">
          <button name="Press" />
        </data>
      </xf:instance>
      <xf:message ev:event="data">data</xf:message>
    </xf:model>
  </head>
  <body>
    <xf:trigger ref="button">
      <xf:label ref="@name" />
      <xf:action ev:event="DOMActivate">
        <xf:dispatch targetid="model">
          <xf:name value="name(context())" />
        </xf:dispatch>
        <xf:setvalue ref="@name" value="name(context())" />
      </xf:action>
    </xf:trigger>
  </body>
</html>

(The stylesheet is loaded from http://www.agencexml.com/xsltforms/xsltforms/xsltforms.xsl.)

Reason seems to be that the in-scope evaluation context ctx is not passed as a second argument to bind_evaluate when xf:dispatch/xf:name/@value is evaluated: https://github.com/AlainCouthures/xsltforms/blob/6e8fa26939252fd7b1bff777bbee28fa6b0d1476/src/js/actions/XFDispatch.js.xml#L50

AlainCouthures commented 2 months ago

Yes, this is an issue in dispatch action processing: the current context is ignored and the default context is used instead.

Please check replacing with: .bind_evaluate(this.subform, ctx, this.element)

The corresponding fix will be committed as soon as possible.