Search code examples
xpathxformsxsltforms

Dynamically changing the xpath expression of a binding element


I'm trying to reuse a subform by calling it with different datanodes, e.g. by clicking a trigger that changes the xpath expression and then loads the subform.

To do that, I created a binding element but I can't make it change dynamically. I know how to change the instance nodes values, so I make my bind element to point to a node, but it doesn't work. Something like this:

<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 xmlns="">
            <xf:instance>
                <tmp>
                    <configuration uri="/tmp/props"/>
                    <props>
                        <prop id="demo id 1" value="demo value1"/>
                        <prop id="demo id 2" value="demo value2"/>
                    </props>
                </tmp>
            </xf:instance>
            <xf:bind id="dynamicNodeset" nodeset="string(/tmp/configuration/@uri)"/>
        </xf:model>
    </head>
    <body>
        <xf:repeat bind="dynamicNodeset">
            <xf:output ref="prop/@id"/>
            <xf:input ref="prop/@value" class="xforms-value"/>
        </xf:repeat>
    </body>
</html>

I also tryed this with no success:

<xf:bind id="dynamicNodeset" nodeset="/tmp/configuration/@uri[string()]"/>
Any idea how can I achieve this? 

And also via Js:

function changeBinding(modelId, bindId, newNodeset){

    var model = document.getElementById(modelId).xfElement;  
    window.XsltForms_globals.openAction("XsltForms_change");

    model.binds[0].nodeset = newNodeset;

    model.setRebuilded(true);
    model.addChange(bind);
    window.XsltForms_globals.addChange(model);
    window.XsltForms_globals.closeAction("XsltForms_change");
    window.XsltForms_globals.refresh();
}

Thanks in advance.


Solution

  • There is no evaluate function in XPath 1.0 but, as a workaround, if the variable part of the expression is limited, you can always use just a predicate to select the corresponding element such as in /tmp/*[name() = substring-after(/tmp/configuration/@uri, '/tmp/)].