W3C home > Mailing lists > Public > public-xml-processing-model-wg@w3.org > July 2006

Re: p:for-each

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 27 Jul 2006 09:44:21 +0100
Message-ID: <44C87CE5.4090308@jenitennison.com>
To: public-xml-processing-model-wg@w3.org


Norm Walsh wrote:
> / Jeni Tennison <jeni@jenitennison.com> was heard to say:
> | (Given no joins as discussed below:) In a p:for-each, there must be
> | exactly one p:declare-input that has a @ref-each attribute (and may
> | have a @select attribute to indicate iteration over elements). This
> | p:declare-input tells you what you're iterating over.
> Given that there must be exactly one, is there a compelling reason to
> do this with a p:declare-input as opposed to simply allowing those
> attributes on the p:for-each element?

I have five reasons:

1. For symmetry with <p:declare-output> in <p:for-each>
2. To provide a place for the naming of the input, as opposed to the 
loop itself
3. For symmetry with <p:declare-input> in <p:choose> (if we have them)
4. For symmetry with <p:declare-input> for other inputs in <p:for-each> 
(if we have them)
5. For extensibility should we choose (in some future version) to allow 
multiple inputs over which we iterate

I guess that 3 is the most compelling reason. If you use attributes on 
<p:for-each>, you end up with something like:

   <p:for-each name="loop"
     <p:declare-output port="validated" />
     <p:declare-output port="errors" />

     <p:step kind="validate" name="validate">
       <p:input port="document" ref="#loop/chapter" />
       <p:output port="validated" ref="#loop/validated" />
       <p:output port="errors" ref="#loop/errors" />

i.e. you need a @name to name the <p:for-each> and a @input-name to name 
the input. This is ugly.

> It seems confusing to me that one p:declare-input is required, but others
> are optional. So you could wind up with
>   <p:for-each name="loop">
>     <p:declare-input port="doc" ref-each="..."/>
>     <p:declare-input port="style" ref="..."/>
>     <p:declare-output port="results" ref="#x/y"/>
>     ... ref="#loop/doc"
>     ... ref="#loop/style"
>     ... ref="#otherstep/foo"
>   </p:for-each>
> It seems to me that you should declare all the inputs or none of them,
> declaring only some just makes my head hurt.

I'd be very happy if you could only declare the input that you're 
iterating over. I'd be unhappy if you had to declare all the inputs. I'm 
moderately happy if you can do either, or declare only some of the inputs.

> | It's a familiar thing to XPath 2.0 users ;)
> | for $i in (a,b,c), $j in (x,y) return ($i,$j)
> I avoid 'for'. Ought not to have been in XPath 2.0 dang it. :-)



Jeni Tennison
Received on Thursday, 27 July 2006 09:17:51 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:32:40 UTC