Search code examples
xforms

XForms, XSLTForms outer join


I have an XForm survey. I'd like to keep the questions in a separate xf:instance of the same model from the xf:instance that collects the answers. In one instance, a group containing 10 questions. In a second instance, a group to hold the 10 answers. The second instance will be submitted. So, this is similiar to a join between two lists.

I've tried using logic like the following:

<xf:output ref="instance('questions')/question[position()]/@text"></xf:output>

but that position() is always returning 1, because the context is of the questions xf:instance. Using the index('current-repeater') updates all 10 displayed questions to be the question at the index of the most recently focused repeat iteration.

Is there a way to use a temporary variable in the xpath to accomplish this? I've tried various uses of $variables and even:

<xf:output ref="instance('questions')/question[position() = (count(current()/preceding-sibling::*) + 1)]/@text"></xf:output>

Thanks,

Jason


Solution

  • Well, it turns out this is currently not supported:

    Axes such as "preceding-sibling::" are not yet supported by the XPath analyzer of XSLTForms, which is written with XSLT 1.0.

    Instead, do something along these lines:

    <xf:instance id="positions">
      <data xmlns="">
        <position />
      </data
    </xf:instance>
    
    ...
    
    <xf:setvalue ref="instance('positions')/position">1</xf:setvalue>
    <xf:setvalue ref="instance('positions')/position" value="count(instance('main')/path/to/things/thing)-1" />
    etc.
    

    Then to use them:

    <xf:input ref="path/to/things/thing[instance('positions')/position]"> ...
    

    From xsltforms-support@lists.sourceforge.net