[xquery-talk] index-of() behavior

Geert Josten Geert.Josten at daidalos.nl
Thu Mar 19 16:40:05 PST 2009


Hi Joe,

I wouldn't be surprised when index-of() happens to work on atomic values only. I think using the 'at' keyword of the for loop is much easier:

for $child at $index in $content/y
return
     <result>{$index}</result>

Kind regards,
Geert

>


Drs. G.P.H. Josten
Consultant


http://www.daidalos.nl/
Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665 JZ Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
http://www.daidalos.nl/
KvK 27164984
De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.


> From: talk-bounces at x-query.com
> [mailto:talk-bounces at x-query.com] On Behalf Of Joe Wicentowski
> Sent: donderdag 19 maart 2009 16:28
> To: talk at x-query.com
> Subject: [xquery-talk] index-of() behavior
>
> Hi all,
>
> Can anyone shed some light on the following question?  I'm
> trying to use fn:index-of() to derive the sequential
> appearance of elements -- in this case, I have 2 <y>
> elements, and I want index-of() to return the values 1 and 2:
>
> <results>{
> let $content :=
>     <x>
>         <y n="1">z</y>
>         <y n="2">z</y>
>     </x>
> for $child in $content/y
> let $index := fn:index-of($content/y, $child) return
>     <result>{$index}</result>
> }</results>
>
> I expected this to return:
>
> <results>
>    <result>1</result>
>    <result>2</result>
> </results>
>
> but instead it returns:
>
> <results>
>    <result>1 2</result>
>    <result>1 2</result>
> </results>
>
> If, on the other hand, I change $content to
>
>     <x>
>         <y n="1">z1</y>
>         <y n="2">z2</y>
>     </x>
>
> Then I get my desired result.  Shouldn't fn:index-of() index
> against the unique <y> nodes rather than their text content?
> I've tested this in eXist 1.3 and in oXygen (using Saxon 9).
>
> Thanks,
> Joe
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
>




More information about the talk mailing list