Re: position vs index

Norman Walsh wrote:
> That is, the position function evaluated in the context of the
> for-each counts the iterations through the sequence, but the position
> function evaluated in the context of the inputs passed to the
> string-replace function only ever sees one document because it doesn't
> receive a sequence.

Yes, I agree that the p:string-replace step only ever sees one document 
because it doesn't receive a sequence.

Also:

<p:for-each select="/list/item"><!-- NB: 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>

returns:

<item v="1" s="1">one</item>
<item v="1" s="2">two</item>
<item v="1" s="3">three</item>
<item v="1" s="4">four</item>

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>

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 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).

Cheers,

Jeni
-- 
Jeni Tennison
http://www.jenitennison.com

Received on Wednesday, 23 May 2007 14:47:52 UTC