I like InfoPath, but was a bit reserved at first... and as a developer I have found InfoPath immensely frustrating at times - it takes a mind shift to really get productive with it. Given this, I thought I'd share a couple of postings I have found invaluable.

The first one is for situations where you want to copy some data from the secondary (lookup) data source into the main form data source (read post here). The second essential piece of information was given at the bottom of the post, is that you'll more than likely need to use the current() function (as soon as you are using a Repeating Group/Section). Thankfully they also posted some tips on using the current() function. When editing the XPath for the Filter, setting the "secondary-data-source-ID is equal to main-data-source-ID" you need to change the main-data-source-ID to use the current() function.

So in my scenario the default filter XPath looked like this: (line breaks entered to make more readable)

xdXDocument:GetDOM("References")
/SystemArea/References/Reference/URLs/URL[../../ReferenceID =
xdXDocument:get-DOM()
/ns1:Question
/my:UrlReferences
/my:UrlReference/ns1:ReferenceID]

Which I edited to the following:

xdXDocument:GetDOM("References")
/SystemArea/References/Reference/URLs/URL[../../ReferenceID = current()/../ns1:ReferenceID]

It helps if you understand your XML schema to do this, but some trial and error might get you there.