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

Re: position vs index

From: Henry S. Thompson <ht@inf.ed.ac.uk>
Date: Wed, 06 Jun 2007 12:34:22 +0100
To: Norman Walsh <ndw@nwalsh.com>
Cc: public-xml-processing-model-wg@w3.org
Message-ID: <f5bodjte2pt.fsf@hildegard.inf.ed.ac.uk>

Hash: SHA1

Norman Walsh writes:

> Do we agree that *outside* the context of a for-each, if the input to
> this step is a sequence of three documents:
>   <p:matching-documents>
>     <p:option name="test" value="p:position() mod 2 = 1"/> <!-- NB: value= -->
>   </p:string-replace>
> then the p:position() function will return "1" for the first document,
> "2" for the second document, and "3" for the third document in the
> sequence?
> If so, then *inside* the context of a for-each, where the input
> to this step is a single document (from the 'current' port):
>   <p:matching-documents>
>     <p:option name="test" value="p:position() mod 2 = 1"/> <!-- NB: value= -->
>   </p:string-replace>
> the p:position() function must return 1 for the first (and only)
> document that matching-documents step sees on its input port.
> Anything else would seem wildly inconsistent.
> However, if you arrange to have p:position() evaluated before being
> passed to the step, i.e., if you use select= instead of value=, then
> p:position() is evaluated in the context of the for-each where the
> natural thing to do is count the number of documents that have passed
> by.

OK, so now I see where things have gone wrong.  In my original
proposal [1], I distinguised between two _different_ counters:

 2) A 1-origin index of the position of the current document in a
    document sequence;

 3) A 1-origin indicator of the iteration number.

Your example provides some motivation for why we might imagine that
these should be different.  I agree that by careful adjustment of
semantics of position() wrt the evaluation point you can get the
desired effect, but I think in practice it will be difficult to define
precisely and difficult to explain -- do we have any other examples
where crossing the threshold of the component changes the value of an
expression in the way you propose?

I'm left feeling that it will be easier to explain and implement if we
keep position() for position in a sequence, and add p:index() for
iteration count.


[1] http://lists.w3.org/Archives/Public/public-xml-processing-model-wg/2007May/0069.html
- -- 
 Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                     Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
            Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
                   URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Version: GnuPG v1.2.6 (GNU/Linux)

Received on Wednesday, 6 June 2007 11:34:33 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:21:52 GMT