Hi @tejashri12 -
You can try using the below code that should display the desired output:
<% var ctx = XML(rtEvent.ctx); %>
<% for(var i=1;i <= ctx.childNodes.length/2;i++){%>
<%=escapeXmlStr(ctx["firstName"+i])%> <%=escapeXmlStr(ctx["age"+i])%>
<% }%>
In this code, the childNodes property of the ctx object is used to determine the number of elements in the ctx object.
Since each child node represents one firstName and one age element, the number of child nodes is divided by 2 to get the number of firstName elements. The code then loops over this number and uses square bracket notation to access the firstName and age elements for each iteration.
Finally, the escapeXmlStr function is used to escape any characters that have a special meaning in XML, to ensure that the output is properly formatted.