Re: position vs index

/ Jeni Tennison <jeni@jenitennison.com> was heard to say:
| And depending on how p:string-replace is defined,
|
| <p:for-each><!-- NB: not selecting items here -->
|   <p:iteration-source>
|     <p:inline>
|       <list>
|         <item v="test" s="test">one</item>
|         <item v="test" s="test">two</item>
|       </list>
|     </p:inline>
|     <p:inline>
|       <list>
|         <item v="test" s="test">three</item>
|         <item v="test" s="test">four</item>
|       </list>
|     </p:inline>
|   </p:iteration-source>
|   <p:output port="result"/>
|
|   <p:string-replace>
|     <p:option name="match" value="item/@v"/>
|     <p:option name="replace" value="position()"/> <!-- NB: value= -->
|   </p:string-replace>
|
|   <p:string-replace>
|     <p:option name="match" value="item/@s"/>
|     <p:option name="replace" select="position()"/> <!-- NB: select= -->
|   </p:string-replace>
| </p:for-each>
|
| could return:
|
| <item v="1" s="1">one</item>
| <item v="2" s="1">two</item>
| <item v="1" s="2">three</item>
| <item v="2" s="2">four</item>
|
| or:
|
| <item v="1" s="1">one</item>
| <item v="1" s="1">two</item>
| <item v="1" s="2">three</item>
| <item v="1" s="2">four</item>

I would have expected the latter.

| That comes down to whether the definition of p:string-replace says
| that when evaluating the 'replace' expression, the context position is
| set to the position of the context node amongst the other matched
| nodes (which would give the former), or that it's always set to 1
| (which would give the latter).

I think we could define it either way, but I don't naturally expect a
match pattern to "know" about the other matches.

| I really don't know how to define a p:position() function to give
| these results, unless it does exactly the same as the position()
| function (i.e. return the context position).

Yes, you win :-)

                                        Be seeing you,
                                          norm

-- 
Norman Walsh <ndw@nwalsh.com> | Young men think old men are fools; but
http://nwalsh.com/            | old men know young men are
                              | fools.--George Chapman

Received on Thursday, 24 May 2007 13:50:44 UTC