Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

XPATH + //


Former Community Member

I am trying to use the XPATH expression "//" to find all matches of an element name no matter where they exist in the XML document.  For example ..


it correctly returns a value of 5 on my test XML document.  Great.  How would I go about grabbing the 3rd match or perhaps iterating through all matches?

I have tried the following


this works.  However, the following doesn't work


It says the XML variable I assign the expression to is <empty>

I even tried to get it to work with a list variable (xml subtype) and assign //process_data/xml_data//User to the variable.  That doesn't work, it shows <list><null/></list> as the result.

I created an xml variable and assign //process_data/xml_data//User to the variable.  That doesn't work, it only shows the 1st match.

Any ideas?

One of the LC Knowledge bases specificaly says this.

/process_data/formVariable/object/data/xdp/datasets/data//TextField1 returns "Hello world 1...", "Hello world 2...", and "Hello world 3..." and therefore is more flexible if the exact structure of an XML is not known (for example, when using a relative path).

3 Replies


Former Community Member

LC is pretty finicky. Although you may define a process variable as an int and use it as a List or XPath index you still have to wrap it in a number function. For example,


rather than


Give it a try.




Looks like you have encountered a bug in the product .

While the //Person xPath query does in fact return the correct number of nodes found within the XML source, it appears that there is some eroneous logic in processing the xPath statement when nodes are childeren of a different parent. For example, when I run some tests on the XML you sent me:

I can infact return node //Person[1] and Person[2] which are children of <Engineers/>. LC seems to not be able to locate the <Person/> nodes under <Administrators> and <Students/>.

I will log this on your behalf. I tried several alternatives with setValue but I was unable to find a workaround. My only suggestion is to create a custom component and implement SAX APIs to locate the values you need.


Former Community Member

Steve ... Yes, I had tried wrapping my index in a number() function.  And to make sure that wasn't the issue, I hard coded the number [2] and it still didn't work.

Marcel ... Yup.  I just built a DSC to work around the issue.