问题
I have a number of forms that all reference a 'Header' Section Template. I would like to reference a control in this section template from another control in the form. (Using the method shown here: Write constraint to validate a field based on the value entered in another field in Orbeon Form Builder)
I get the following error when I try to reference a control named 'section' in the section template:
Undeclared variable in a standalone expression: $section
Here is the XPath Expression I am using:
if($section = 'PKP' or $section = '') then true() else false()
There is a control named 'section' in the Section Template, but it appears that it is not accessible from the rest of the form.
Does anyone know if it is possible to reference a control that is in a 'Section Template' in Orbeon form builder?
回答1:
As you noticed, you can't access the value for a field of a section template outside of that section using named $gaga
, assuming that the field name is gaga
. This is because you could have multiple "instances" of the same section template in your form. Imagine you have an "address" section template, and you insert it twice in the form for the "Billing address" and "Shipping address". Then if using $city
outside of those section templates, you wouldn't know if it refers to the City field in the billing or shipping address.
Instead, when adding the section template to the form, you'll want to assign a name to those sections (say billing-address
) and use an XPath expression such as /form/billing-address/city
to reference the value of the city field in the billing address.
回答2:
I dont use Form builder for developing forms, but based on the error, see if there is code for variable declaration for $section. Anything that starts with $ is meant as variable, hence a variable declaration is required. If a variable is declared the corresponding line might look this
<xxforms:variable name="section" select="<some_xpath_expression_here>" />
If you dont want to use a variable then try referring with nodeset. You can write the nodeset like this assuming that 'section' is in 'my-instance' model instance.
if(instance('my-instance')/section = 'PKP' or instance('my-instance')/section = '') then true() else false()
来源:https://stackoverflow.com/questions/7590420/orbeon-form-builder-referring-to-a-control-within-a-section-template