问题
I use Orbeon Forms and I want to set a dynamic class name on a div
or span
(or any non-XForms tags like xforms:output
) so that group of controls can be set with that CSS class.
<div class="color-with-{if(/fetch/data1='Yes') then 'green' else 'red'}">
But this is not working. When I look at the HTML source code after the form is rendered it seems it did not processed that dynamic part.
<div class="color-with-{if(/fetch/data1='Yes') then 'green' else 'red'}"
id="xf-279">
However this dynamic assignment works pretty good with Orbeon tags.
<xforms:output value="if ((xxforms:valid(instance('account-opening-setup'),true()))
and (xxforms:valid(instance('form-variables'),true())))
then 'Complete' else 'Incomplete'"
class="validation-{if ((xxforms:valid(instance('account-opening-setup'),true()))
and (xxforms:valid(instance('form-variables'),true()))) then 'complete'
else 'incomplete'}" />
Please advise which HTML tag I can use to dynamically assign a class name so that group of controls follow that class CSS.
回答1:
Those expression that use the {...XPath...}
syntax are called attribute value templates (AVT), and Orbeon Forms support them in a number of XForms attributes and HTML attributes, including class
and style
. So your code above should be working.
It might be the case that the AVT is not interpreted because your div
isn't in the XHTML namespace. My recommendation is to always use a prefix on your elements. Define the xmlns:xhtml="http://www.w3.org/1999/xhtml"
on the root element, and then use xhtml:div
instead of div
. If you find this too inconvenient, make sure you have the XHTML namespace as your default namespace declared on the root element, with xmlns="http://www.w3.org/1999/xhtml"
.
来源:https://stackoverflow.com/questions/7415713/which-html-tag-can-be-used-to-accept-dynamic-class-name-in-orbeon-forms