@context id

From W3C XForms Group Wiki (Public)
Jump to: navigation, search


Add optional ID argument to the XForms 1.1 function context().


Incorporated into XForms 2.0, in review


context() accesses only the parent context, not any other ancestor (or other element) context.

For repeat/setvalue, context() accesses the repeat context.

For repeat/repeat/setvalue, or worse yet repeat/repeat/repeat/setvalue, it is impossible to access the grand-parent contexts using context, and authors revert to using index() and position() in predicates. So, the authoring curve becomes steep.


See the discussion [1]


Should we limit the context() ID argument to lexically enclosing elements?

An IDREF would have to be interpreted using the same kind of logic used elsewhere to convert IDREFs in the authored DOM into element references in the run-time "multi-DOM". Selecting the right repeat-item occurrences is based on where the invocation that makes the IDREF is located relative to the element being referenced. That being said, limiting to IDREFs seems too constraining, based on the example use case below. Notice that it refers to a repeat when really it wants to refer to the (unexpressed) child group element of that repeat. We could say someone wanting to do this should express a child group element for the repeat and assign it an ID, but it is a fairly technical thing to ask of authors.

Use Case

The following use case has not yet been proofread or checked.

NOTE: The in-scope evaluation context of the group with id="hotel" is a single hotel element, one from the nodeset of the parent repeat with id="hotels-repeat". The invocation context('hotel') returns the hotel corresponding to the containing group.

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    <title>Hotel requests</title>
    <style type="text/css">
      .heading { display: div; color: blue; font-size: 16pt;}
    <model xmlns="http://www.w3.org/2002/xforms">
      <instance id="hotels" resource="hotels.xml" />
      <instance id="mark-request">
        <data xmlns="">
          <name />
      <submission id="mark-status" method="post" resource="/hotel"
		  replace="instance" instance="hotels" />
      <instance id="statuses">
	<data xmlns="">
      <xf:repeat id="status-repeat" nodeset="instance('statuses')/statuses/status">
	<xf:output class="heading" ref="."><xf:label>Status: </xf:label></xf:output>
        <xf:repeat id="hotels-repeat" nodeset="instance('hotels')/hotel[status=current()]">
          <xf:group id="hotel"> 
             <xf:output value="name">
               <xf:label>Name: </xf:label>
             <xf:repeat id="set-status-repeat" nodeset="instance('statuses')/statuses/status[context('status-repeat')/status != .]">
                 <xf:label>Mark <xf:output ref="context('set-status-repeat')" /></xf:label>
                 <xf:action ev:event="DOMActivate">
                   <xf:setvalue ref="instance('mark-request')/name" value="context('hotel')/name" />
                   <xf:send submission="mark-status" />

Sample Instance Data

<?xml version="1.0"?>
    <name>Dew Drop Inn</name>
    <name>Popular Place</name>
    <name>Motel Zero</name>
    <name>FlyBuzz In</name>