[xquery-talk] sorting not working

Cindy Girard clm6u at virginia.edu
Fri Nov 18 10:45:40 PST 2005


Ouch - big mistake. Thanks!

MK> As someone else spotted and I didn't, $copies//printdate is not going to
MK> select anything when $copies is an attribute node.

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

>> -----Original Message-----
>> From: talk-bounces at xquery.com 
>> [mailto:talk-bounces at xquery.com] On Behalf Of Cindy Girard
>> Sent: 18 November 2005 15:26
>> To: talk at xquery.com
>> Subject: Re[2]: [xquery-talk] sorting not working
>> 
>> OK - a little more info:
>> We're using eXist.
>> 
>> 
>> The three document segments:
>> 
>> nnr.b.xml
>>             <compdate value="1788.B">c. 1788</compdate>
>>             <printdate value="1794.A">c. 1794</printdate>
>> 
>> nnr.l.xml
>>             <compdate value="1788.B">c. 1788</compdate>
>>             <printdate value="1795">c. 1795</printdate>
>> 
>> nnr.g.xml
>> 
>>             <compdate value="1788.B">c. 1788</compdate>
>>             <printdate value="1794.C">c. 1794</printdate>
>> 
>> The order it comes out as is:
>> nnr.g, nnr.b, nnr.l
>> 
>> and it should be:
>> nnr.b, nnr.g, nnr.l
>> 
>> (Is the '.A' '.C' throwing it off? We use the same ordering in another
>> place and it works fine.)
>> 
>> I've changed the code to this:
>> 
>>          order by ($copies//compdate)[1]/@value, 
>> ($copies//printdate)[1]/@value
>> 
>> with no change.
>> 
>> original code:
>> 
>>  {for $copies in 
>> collection($g:collection)/bad[starts-with(@id, $workid)]/@id
>>  let $bad :=collection($g:collection)/bad[@id = $copies]
>>  let $copyversion := string($bad/@copy),
>>        $comporder :=$bad[@id = $copies]//compdate[1]/@value,
>>        $printorder :=$bad[@id = $copies]//printdate[1]/@value,
>>        $printdate := $bad[@id = $copies]//printdate/text(),
>>        $repository := $bad//repository/institution/text(),
>>        $repcount := count($repository)
>>           order by $copies//compdate[1]/@value, 
>> $copies//printdate[1]/@value
>>  return
>>  if ($copies != $copyid)
>>  then
>>  <option value="{$copies}"><striptags>{if(exists($copyversion))then
>>  <wrap>{$copyversion}, </wrap>else ""} {string($printdate)}
>>  ({if($repcount = 1) then $repository else <wrap>Multiple
>>  ({$repcount}) Institutions</wrap> })</striptags></option>
>>  else ""
>>  }
>> 
>> 
>>  Thanks,
>>  Cindy
>> 
>> MK> It would help to (a) provide a sample source document, 
>> and (b) to say what
>> MK> product you are using.
>> 
>> MK> Also "not working" is very unspecific: what output/error 
>> do you get?
>> 
>> MK> The only thing I can see that's questionable is the 
>> repeated use of
>> 
>> MK> x//compdate[1]
>> 
>> MK> This selects every compdate descendant that is the first 
>> compdate child of
>> MK> its parent. I suspect you intended to select the first 
>> descendant compdate
>> MK> element, which can be written
>> 
>> MK> (x//compdate)[1]
>> 
>> MK> or
>> 
>> MK> x/descendant::compdate[1]
>> 
>> MK> Michael Kay
>> MK> http://www.saxonica.com/
>> 
>> 
>> 
>> 
>> 
>> >> -----Original Message-----
>> >> From: talk-bounces at xquery.com 
>> >> [mailto:talk-bounces at xquery.com] On Behalf Of Cindy Girard
>> >> Sent: 17 November 2005 20:46
>> >> To: talk at xquery.com
>> >> Subject: [xquery-talk] sorting not working
>> >> 
>> >> Hi.
>> >> 
>> >> Is there another way I can word this? I'm just not sure where the
>> >> error is.
>> >> 
>> >> Thanks,
>> >> Cindy
>> >> 
>> >> -------------------------------------
>> >> 
>> >> {for $copies in collection($g:collection)/bad[starts-with(@id 
>> >> , $workid)]/@id
>> >> let $bad :=collection($g:collection)/bad[@id = $copies]
>> >> let $copyversion := string($bad/@copy),
>> >>       $comporder :=$bad[@id = $copies]//compdate[1]/@value,
>> >>       $printorder :=$bad[@id = $copies]//printdate[1]/@value,
>> >>       $printdate := $bad[@id = $copies]//printdate/text(),
>> >>       $repository := $bad//repository/institution/text(),
>> >>       $repcount := count($repository)
>> >>          order by $copies//compdate[1]/@value, 
>> >> $copies//printdate[1]/@value
>> >> return 
>> >> if ($copies != $copyid)
>> >> then
>> >> <option 
>> >> value="{$copies}"><striptags>{if(exists($copyversion))then 
>> >> <wrap>{$copyversion}, </wrap>else ""} {string($printdate)} 
>> >> ({if($repcount = 1) then $repository else <wrap>Multiple 
>> >> ({$repcount}) Institutions</wrap> })</striptags></option>
>> >> else "" 
>> >> 
>> >> }
>> >> 
>> >> 
>> >> 
>> >> _______________________________________________
>> >> talk at xquery.com
>> >> http://xquery.com/mailman/listinfo/talk
>> >> 
>> 
>> 
>> MK> _______________________________________________
>> MK> talk at xquery.com
>> MK> http://xquery.com/mailman/listinfo/talk
>> 
>> 
>> 
>> -- 
>> - Cindy 
>> 
>> _______________________________________________
>> talk at xquery.com
>> http://xquery.com/mailman/listinfo/talk
>> 


MK> _______________________________________________
MK> talk at xquery.com
MK> http://xquery.com/mailman/listinfo/talk



-- 
- Cindy 



More information about the talk mailing list