Innes,
Try this
<foreach variable="singleNewsItem" items="$listOfItems/*:newsItem">
<display message="Here's one item:" variable="$singleNewsItem"/>
</foreach>
This selects the newsitem irrespective of the namespace. You can also try qualifying it with the correct namespace.
-Satya.
dev/jackbe.
Hi Satya,
Cheers for that. I'll give that a go, but I also managed to get some output by changing the items value in the foreach declaration to:
<foreach variable="singleNewsItem" items="$clipResult//newsItem">
Wohoo ... output at last! So I'm on my way again!
Cheers, Innes (NZ)
Hi Innes,
On closer look, it is not a namespace issue. When you say <foreach variable="singleNewsItem" items="$listOfItems/newsItem > it means that there should've been a newsItem inside each item in the list. So it never gave an output.
<foreach variable="singleNewsItem" items="$clipResult/elements/newsItem > would've returned a valid result. The assign isn't needed.
When you said <foreach variable="singleNewsItem" items="$clipResult//newsItem"> it meant "get all newsItem from anywhere in the document". Hence the variable gets assigned to each news item by turn. Hence a valid output.
I guess you figured it by now. But just reiterating for benefit of anyone else looking at this post.
Cheers,
Satya.



Afternoon fellow Mashers ...
I'm losing the will to live ... well not really, but today the learning curve just seems that much steeper. Well, enough whinging and on to my problem.
I can't quite get the hang of the foreach loop in EMML. I'm sure its the way I'm constructing the items value, but do you think I can figure out what I'm doing wrong. I suspect that's the way the XPath value is specified, but I'm not sure. Let's start with my EMML code which appears below.
Now I thought this would produce some output results, but nooooo ... just an empy document. I have used the debug tool and determined that $clipResult returns data, and that $listOfItems is also populated, but the display in the foreach loop produces only a empty document.
I've attached a screenshot of the structure returned from the original invoke in case that helps too.
Suggestions ...
Many thanks, Innes (NZ)
<operation name="myTestMashup">
<output name="myOutput" type="document" />
<input name="dappName" type="string" default="DairyNZCurrentNews" />
<variables>
<variable name="clipResult" type="document"></variable>
<variable name="listOfItems" type="document"></variable>
<variable name="singleNewsItem" type="document"></variable>
</variables>
<invoke service="DairyNZNews" operation="getData"
inputvariables="dappName" outputvariable="clipResult" />
<assign fromexpr="$clipResult/elements/newsItem" outputvariable="listOfItems" />
<display message="*************** Start of listofItems ******************" />
<display variable="$listOfItems" />
<display message="*************** End of listofItems ******************" />
<foreach variable="singleNewsItem" items="$listOfItems/newsItem">
<display message="Here's one item:" variable="$singleNewsItem"/>
</foreach>
</operation>