Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Locating XML Element - Predicate

Avatar

Level 1

Hello,

I am trying to bind a text field in Designer 8.1 to a specific XML element.

An example of the XML structure:

<KeyValueGroup>

     <ID>

          <Name>Name1</Name>

          <Value>Value1</Value>

     </ID>]

     <ID>

          <Name>Name2</Name>

          <Value>Value2</Value>

     </ID>

     <ID>

          <Name>Name3</Name>

          <Value>Value3</Value>

     </ID>

</KeyValueGroup>

I have been trying to bind using $record.KeyValueGroup.ID[Name="Name2"].Value to return the value of the Name2 property, however Designer rejects this expression.

Would anyone be able to advise where I am going wrong?

I understand I could achieve this using a Javascript function that enumerates the ID array, but would prefer to find a solution not involving javascript if possible.

Any help much appreciated,

Matt

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Matt,


The $record refers to the current subtree of the Data DOM, so in your case $data.KeyValueGroup and $record are the same thing.


You also need a "." before the predicate.


Anyway, try  $record.ID.[Name=="Name2"].Value


Good Luck


Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi Matt,


The $record refers to the current subtree of the Data DOM, so in your case $data.KeyValueGroup and $record are the same thing.


You also need a "." before the predicate.


Anyway, try  $record.ID.[Name=="Name2"].Value


Good Luck


Bruce

Avatar

Level 1

Many thanks Bruce!

Your solution worked perfectly and I have learnt something in the process!

It makes so much sense to have the "." before the predicate but it was something that never occurred to me!

Have a wonderful day,

Matt