Domanda

I'm making my own component in XBL and I have to use a submission within it. I have two parameters (resource, XPath) of the submission which users can provide in Form Builder (like with the autocomplete control):

<xbl:binding element="fr|myControl" id="fr-myControl" xxbl:mode="lhha binding value">
<metadata xmlns="....">
.... 
<templates>
    <instance label=""/>
    <view>
        <fr:myControl id="" appearance="minimal" xpath="" xmlns="" resource="" >
            <xf:label ref=""/>
            <xf:hint ref=""/>
            <xf:help ref=""/>
            <xf:alert ref=""/>
        </fr:myControl>        
    </view>
</templates>

<control-details>
    <xf:input ref="@resource">
        .... 
    </xf:input>
    <xf:input ref="@xpath">
        .... 
    </xf:input>
</control-details>        
</metadata>
.... 

And then I want to call a REST submission, with resource and result XPath provided by the user in form builder (@resource and @xpath):

<xf:model>
<xf:instance id="result"><value/></xf:instance>   
<xf:instance id="sub"><value/></xf:instance>  
<xf:instance id="resource"><value/></xf:instance>  
<xf:instance id="xpath"><value/></xf:instance>      
.... 
<xf:submission id="my-submission" instance="sub" 
mediatype="application/xml" 
method="get" 
resource="{instance('resource')}"   
replace="instance" 
serialization="none"/>                    
    <xf:action id="populate-data-binding">                          
        <xf:action context="instance('sub')" 
        ev:event="xforms-submit-done" 
        ev:observer="my-submission">                      
            <xf:action>                                                                      
                <!-- there is a problem-->
                <xf:var as="xs:string" name="control-value" value="instance('xpath')"/>                            
                <xf:setvalue ref="instance('result')" value="$control-value"/>
            </xf:action>                
        </xf:action>            
    </xf:action>
</xf:model>

.... 

<xf:var name="resource-avt" xbl:attr="xbl:text=resource" xxbl:scope="outer"/>
<xf:var name="resource" xbl:attr="xbl:text=resource" >
    <xf:action ev:event="xforms-enabled xforms-value-changed">
        <xf:setvalue ref="instance('resource')" value="$resource"/>
    </xf:action>
</xf:var>

<xf:var name="xpath-avt" xbl:attr="xbl:text=xpath" xxbl:scope="outer"/>
<xf:var name="xpath" xbl:attr="xbl:text=xpath" as="xs:string">
    <xf:action ev:event="xforms-enabled xforms-value-changed">
        <xf:setvalue ref="instance('xpath')" value="$xpath"/>
    </xf:action>
</xf:var>

My problem is in the highlighted line above: in instance('xpath') I have the value of the parameter provided by the user in Form Builder for example: /pathToResult. And I want to get the part of the XML result from the submission resource associated with /pathToResult. But unfortunately in instance('result') there is: /pathToInstance instead of the expected result, for example for the response XML:

<xml>
   <blabla>bla</blabla>
   <pathToResult>MY RESULT !!!</pathToResult>
</xml>

the expected value of result-instance is: MY RESULT !!! instead of /pathToResult.

However if I modified the code like this:

<xf:var as="xs:string" name="control-value" value="/pathToResult"/>

it works well, but in this case the path is hardcoded. I want instead to give opportunity to the Form Builder user to specify the XPath expression in the control configuration.

How can I modify my code to reach expected effect?

È stato utile?

Soluzione

One answer is similar to the one provided for this other question: use saxon:evaluate().

<xf:setvalue ref="instance('result')" value="saxon:evaluate(instance('xpath'))"/>

Another way is as follows. If your local XBL model is under <xbl:template>, then the model can be modified with attributes present on the XBL bound node. So for example:

<xf:submission xbl:attr="resource" ...>

This copies the resource attribute on <fr:mycontrol> to the <xf:submission> element.

This is simpler, and should do exactly what you want.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top