Referencing previous iterations while in p:for-each

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Referencing previous iterations while in p:for-each

Jeff Jones
I have an XPL question I've been scratching my head over for a while,
and I wonder if anyone can help.

I have an OPS-based app, MVC-based, that assembles its model by
executing a "model" document that looks something like this:

<model>  <!-- contains 1..n "datasource" elements -->
     <datasource>
         <!-- grab something from a web service -->
     </datasource>
     <datasource>
         <!-- use the SQL processor to do a database query -->
     </datasource>
</model>

This document gets fed to a pipeline built around this loop:

     <p:for-each href="#model-doc" select="/model/datasource"
root="data" id="aggregated-data">

         <!-- Execute the code in each "datasource" element; the details
don't matter here -->
         <p:processor name="oxf:pipeline">
             <p:input href="current()#xpointer(/datasource/p:config)"/>
             <!-- other inputs -->
             <p:output ref="aggregated-data"/>
         </p:processor>

</p:for-each>

Here's my problem:

Occasionally, I have a case where I need the results of one <datasource>
  in order to execute the next one. For example, I might do a search
against a web service in the first <datasource>, and then need something
from the search results to use as a key in a database query in the next
<datasource>.

However, once an iteration of the <p:for-each> loop is completed, I
don't see any way to get at its results when I move on to the next
iteration. I apparently can't take the results of my web service call,
for example, and present it to the SQL query as an input.

Does anyone see a way to do this? Have I missed something?

The only solution I've come up with so far is to use the scope
serializer at the end of each iteration to write the results of each
iteration into the request, and then use the scope generator at the
beginning of each iteration to retrieve all the data from all the
previous iterations. This could probably be made to work, but it would
be very inefficient, since I really only need previous-iteration data
about 10% of the time, and I probably can't afford that much of a
performance hit.

So... can anyone suggest anything?

Thanks for reading.

Jeff Jones
TWC Interactive



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Referencing previous iterations while in p:for-each

Erik Bruchez
Administrator
Jeff Jones wrote:

> I have an XPL question I've been scratching my head over for a while,
> and I wonder if anyone can help.
>
> I have an OPS-based app, MVC-based, that assembles its model by
> executing a "model" document that looks something like this:
>
> <model>  <!-- contains 1..n "datasource" elements -->
>     <datasource>
>         <!-- grab something from a web service -->
>     </datasource>
>     <datasource>
>         <!-- use the SQL processor to do a database query -->
>     </datasource>
> </model>
>
> This document gets fed to a pipeline built around this loop:
>
>     <p:for-each href="#model-doc" select="/model/datasource" root="data"
> id="aggregated-data">
>
>         <!-- Execute the code in each "datasource" element; the details
> don't matter here -->
>         <p:processor name="oxf:pipeline">
>             <p:input href="current()#xpointer(/datasource/p:config)"/>
>             <!-- other inputs -->
>             <p:output ref="aggregated-data"/>
>         </p:processor>
>
> </p:for-each>
>
> Here's my problem:
>
> Occasionally, I have a case where I need the results of one <datasource>
>  in order to execute the next one. For example, I might do a search
> against a web service in the first <datasource>, and then need something
> from the search results to use as a key in a database query in the next
> <datasource>.
>
> However, once an iteration of the <p:for-each> loop is completed, I
> don't see any way to get at its results when I move on to the next
> iteration. I apparently can't take the results of my web service call,
> for example, and present it to the SQL query as an input.
>
> Does anyone see a way to do this? Have I missed something?
>
> The only solution I've come up with so far is to use the scope
> serializer at the end of each iteration to write the results of each
> iteration into the request, and then use the scope generator at the
> beginning of each iteration to retrieve all the data from all the
> previous iterations. This could probably be made to work, but it would
> be very inefficient, since I really only need previous-iteration data
> about 10% of the time, and I probably can't afford that much of a
> performance hit.
>
> So... can anyone suggest anything?
You are right that in each iteration, current() returns a new XML
document which does not provide access to previous iterations.

You could work around this by first transforming your model document to
contain things like:

<model>
   <iteration>
     <datasource>

     </datasource>
     <datasource>

     </datasource>
   </iteration>
   <iteration>
     <datasource>

     </datasource>
     <datasource>

     </datasource>
   </iteration>
   ...
</model>

Then you would iterate over <iteration>, and therefore each iteration
would have all the data needed.

-Erik

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Referencing previous iterations while in p:for-each

Jeff Jones
Erik,

Thanks for the reply. I actually solved the problem in the meantime,
using a different approach; I wrote an XSL stylesheet that translates my
   <model><datasource>...</datasource></model> documents into XPL, and
then I just run the generated pipeline through the pipeline processor. I
put an "id" attribute on each <datasource>, and if it needs the output
from a previous <datasource>, I add a "depends" attribute that tells the
translation stylesheet to add the output of the named <datasource> as an
input to the current one. So I guess I've gotten rid of the explicit
iteration altogether.

I've attached the stylesheet if anyone would like to see what I'm
talking about, but I don't have any more questions at this point. Thanks
again for your help.

</Jeff>


Erik Bruchez wrote:

> Jeff Jones wrote:
>> I have an XPL question I've been scratching my head over for a while,
>> and I wonder if anyone can help.
>>
>> I have an OPS-based app, MVC-based, that assembles its model by
>> executing a "model" document that looks something like this:
>>
>> <model>  <!-- contains 1..n "datasource" elements -->
>>     <datasource>
>>         <!-- grab something from a web service -->
>>     </datasource>
>>     <datasource>
>>         <!-- use the SQL processor to do a database query -->
>>     </datasource>
>> </model>
>>
>> This document gets fed to a pipeline built around this loop:
>>
>>     <p:for-each href="#model-doc" select="/model/datasource"
>> root="data" id="aggregated-data">
>>
>>         <!-- Execute the code in each "datasource" element; the
>> details don't matter here -->
>>         <p:processor name="oxf:pipeline">
>>             <p:input href="current()#xpointer(/datasource/p:config)"/>
>>             <!-- other inputs -->
>>             <p:output ref="aggregated-data"/>
>>         </p:processor>
>>
>> </p:for-each>
>>
>> Here's my problem:
>>
>> Occasionally, I have a case where I need the results of one
>> <datasource>  in order to execute the next one. For example, I might
>> do a search against a web service in the first <datasource>, and then
>> need something from the search results to use as a key in a database
>> query in the next <datasource>.
>>
>> However, once an iteration of the <p:for-each> loop is completed, I
>> don't see any way to get at its results when I move on to the next
>> iteration. I apparently can't take the results of my web service call,
>> for example, and present it to the SQL query as an input.
>>
>> Does anyone see a way to do this? Have I missed something?
>>
>> The only solution I've come up with so far is to use the scope
>> serializer at the end of each iteration to write the results of each
>> iteration into the request, and then use the scope generator at the
>> beginning of each iteration to retrieve all the data from all the
>> previous iterations. This could probably be made to work, but it would
>> be very inefficient, since I really only need previous-iteration data
>> about 10% of the time, and I probably can't afford that much of a
>> performance hit.
>>
>> So... can anyone suggest anything?
>
> You are right that in each iteration, current() returns a new XML
> document which does not provide access to previous iterations.
>
> You could work around this by first transforming your model document to
> contain things like:
>
> <model>
>   <iteration>
>     <datasource>
>
>     </datasource>
>     <datasource>
>
>     </datasource>
>   </iteration>
>   <iteration>
>     <datasource>
>
>     </datasource>
>     <datasource>
>
>     </datasource>
>   </iteration>
>   ...
> </model>
>
> Then you would iterate over <iteration>, and therefore each iteration
> would have all the data needed.
>
> -Erik
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

assemble-model-pipeline.xsl (11K) Download Attachment