Custom event context information

From W3C XForms Group Wiki (Public)

(Redirected from PassingEventContext)
Jump to: navigation, search

Custom event context information

The context Element Child of the dispatch Element

The event() function ("7.11.2 The event() Function") allows using event context information from XPath expressions. The context element offers the converse functionality by allowing to pass context information to a newly dispatched event.

name

The name attribute specifies the name of the context information to pass.

select

The optional select attribute specifies an XPath expression returning the context information to pass. With XPath 1.0, the value can be of type boolean, string, number, or node-set. With XPath 2.0, the value can be any sequence of item.

The value of the context information is determined by the following methods, in order of precedence:

  1. the result of evaluating the XPath expression appearing in attribute "select", if specified
  2. the inline string content of the context element (when neither the single node binding nor the "select" attribute are expressed)

Example:


<xf:dispatch name="update-person" target="my-model">
  <!-- The "person" context information is assigned to the node pointed to by "instance('person')" -->
  <xf:context name="person" select="instance('person')"/>
  <!-- The "min-age" context information is assigned the number 12 -->
  <xf:context name="min-age" select="21"/>
  <!-- The "location" context information is assigned the string 'Michelle' -->
  <xf:context name="new-first-name">Michelle</xf:context>
</xf:dispatch>


Using the information:


<xf:action ev:event="update-person">
  <xf:insert context="..." origin="event('person')"/>
  <xf:setvalue ref="..." value="event('min-age')"/>
  <xf:setvalue ref="..." value="event('new-first-name')"/>
</xf:action>


About the use of the select attribute

The choice of a new attribute name, "select", is based on the fact that we cannot use existing attribute names as used in XForms 1.1, namely: "ref" (which points to a single node), "nodeset" (which points to a node-set), and "value" (which in XForms always returns a string). The precedent is the "select" attribute from XSLT.

Another solution could consist in using @value all the way. There are two drawbacks to this:

  • In XForms, @value is currently always used to express that the result is used a string.
  • For variables, if XForms has <variable name="..." value="..."/>, then it is confusing for people used to XSLT.

Open questions:

  • Should the element support the "model", "ref", "bind", and even "value" attributes as well?
    • NickVdB: I think it should be safe to re-use ref (we should 'upgrade' the data model of ref to any sequence)
  • Other actions can support xf:context, including xf:send, and dialog xf:show/xf:hide if introduced.

TODO:

  • Modify "7.11.2 The event() Function": "Each event describes what properties can be accessed by this function and the type and value that will be returned as the result." Mention that this description is not necessarily predefined.

Personal tools