Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Conditional Data Binding

Avatar

Level 2

I would like to bind data to a table only on the condition that one of the child tags has a certain value.

For example, let's say my XML file had the following structure:

<tag>

     <condition>1</condition>

     ....

</tag>

I want to bind only if the condition tag has a value of '1'. Does anyone have an idea how this can be done?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 8

You need to use SOM predicates in your Data Binding expression. For example the binding expression for your entire table with the common parent of <Table> let's say, you could put:

$.Table.[tag.condition.value=='1']

Remember the '.' (period) after Table since that what tells the XFA parser to expect a boolean to determine whether to bind or not.

If you require more detail, please provide more xml and your form names/hierarchies.

Kyle

View solution in original post

4 Replies

Avatar

Correct answer by
Level 8

You need to use SOM predicates in your Data Binding expression. For example the binding expression for your entire table with the common parent of <Table> let's say, you could put:

$.Table.[tag.condition.value=='1']

Remember the '.' (period) after Table since that what tells the XFA parser to expect a boolean to determine whether to bind or not.

If you require more detail, please provide more xml and your form names/hierarchies.

Kyle

Avatar

Level 2

Thanks that resolves my question, but I also want to know how I would be able to use SOM predicates in javascipt code

I tried:

xfa.resolveNode("xfa.datasets.data.tag.[condition.value=='1'].TestValue").value

For an XML structured in this manner, except with multiple tags with different condition values:

<tag>

     <condition>1</condition>

     <TestValue>0</TestValue>

     ....

</tag>

....

Avatar

Level 8

This will return all the tag nodes whose condition element equals 1:

xfa.resolveNodes('$record.tag.[condition=="1"]')

You can also use:

XMLData.applyXPath(xfa.data, "RootNode.tag[condition='1']")

if you're more familiar with xPath expressions. It's also faster (when you get up to around 10,000 entries).

Kyle