Search code examples
orbeon

How to make resource language attribute dynamic in Orbeon Forms?


In my model i define an instance related to form-resources.

I want to set "xml:lang" value dynamically by a xpath expr in a variable.

I tried but the xml:lang attribute of resource element isn't evaluating the variable, but instead it recognises it as string! (xml:lang="$language")

...
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
  <xf:var name="language" value="de" as="xs:string" />
  ...
  <xf:instance id="fr-form-resources" xxf:readonly="false">
    <resources>
      <!-- How "xml:lang" attribute can have dynamic value 
          from a variable/xpath instead of static string 'de' ? -->
      <resource xml:lang="de">
        <IntegerField>
          <label>%translation.IntegerField%</label>
          <IntegerField />
          </Project>
          <cancel>
            <label>%translation.cancel%</label>
            <hint />
          </cancel>
          <ok>
            <label>%translation.ok%</label>
            <hint />
          </ok>
      </resource>
    </resources>
  </xf:instance>
</xf:model>

Is there any way to achieve this?

Using Orbeon 4.5


Solution

  • Use an xf:bind for this; something like:

    <xf:bind
        ref="instance('fr-form-resources')/resource/@xml:lang"
        calculate="$language"/>
    

    This is the general mechanism in XForms to have something an instance automatically calculated and re-evaluated as users interact with the form.