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

XML iteration trouble

Avatar

Former Community Member

Hello all

In my orchestration I have a xml variable like this:

<form>
    <routes>
        <route>
            <elements>
                <foo>xxx</foo>
                <foo>yyy</foo>
                <foo>zzz</foo>
            </elements>

            <elements>
                <foo>ee</foo>
                <foo>ii</foo>
                <foo>kk</foo>
                <foo>aa</foo>
            </elements>
        </route>

        <route>
            <elements>
                <foo>xxx</foo>
            </elements>
            <elements>
                <foo>ff</foo>
                <foo>mmm</foo>
            </elements>
        </route>
    </routes>
</form>

I use a setValue/decisionPoint combination to iterate through it, first of all I get the routes count with an xPath and start a counter like this:

/process_data/@routesCount = count(/process_data/xmlVar/routes/route)
/process_data/@routesCounter = /process_data/@routesCounter +1

Then I go on to iterate inside that routes/route[1] node using the same method, I want to get the number of 'foo' elements inside route[1] so I have the setValue:

/process_data/@fooCount = count(/process_data/xmlVar/routes/route[/process_data/@routesCounter]/elements/foo)

but I'm getting the total foo count of the entire document (10) instead of 3

I have done recording/playback several times, the @routesCount and @routesCounter index work fine, but I always get 10 for the @fooCount.

When I execute the XPath query:

count(/form/routes/route[1]/elements/foo)

in Oxygen I get 3 for a result

Somehow LC is not taking the @routesCounter index into consideration when querying the XML

Have you tried to do this double-iteration stuff?


Thanks for your help

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

This worked for me.

Untitled.png

The attached ES2 .lca contains the XML and the schema used in the archived process.

Steve

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

This worked for me.

Untitled.png

The attached ES2 .lca contains the XML and the schema used in the archived process.

Steve

Avatar

Former Community Member

As the matter of fact, I have checked out some similar process I have working, and noticed I was missing a number() function.

The indices must be cast to number before being able to iterate, so:

/process_data/@fooCount = count(/process_data/xmlVar/routes/route[number(/process_data/@routesCounter)]/elements/foo)

works fine.

Anyway, the intermediate XML var tip was useful too.

Thank you.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----