[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

index-of() behavior

Michael Kay mike at saxonica.com
Thu Mar 19 15:46:26 PST 2009


  index-of() behavior
index-of() compares items by atomizing them and comparing the atomic values
using the eq operator.

What you're trying to do could be achieved simply by

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

but if you want a general function that's like index-of except that it
compares using node identity, you could do

declare function my:index-by-identity($seq as node()*, $srch as node()) {
  for $i at $p in $seq where $i is $srch return $p
}

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: http://x-query.com/mailman/listinfo/talk 
> [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Joe Wicentowski
> Sent: 19 March 2009 15:28
> To: http://x-query.com/mailman/listinfo/talk
> Subject:  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
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.