[xquery-talk] how to remove repetition using distinct value ofstrings

Devineni, Srinivasa (LNG-DAY) srinivasa.devineni at lexisnexis.com
Sat Mar 4 01:45:07 PST 2006


To get distinct values of attribute names, use as below:

distinct-values(for $attr in  $j//author//@* return name($attr))


your modified query now reads:

let $j:=
<bookstore>
<book>
   <author firstname='joe' lastname='carlon' > </author> </book> <book>
   <author firstname='joe' lastname='carlon' > </author> </book> <book>
   <author firstname='mary' > </author> </book>

</bookstore>
 
for $n in distinct-values(for $attr in  $j//author//@* return
name($attr))
  
return

(
   for $v in distinct-values($j//@*[name()=$n])
return
 (
<attr>  name="{$n}" 
 val="{$v}" 
  count = "{count ($j//@*[name()= $n ] [.=$v])}"    
</attr> 

 ) 
)

The above should return you below result:

<attr> name="firstname" val="joe" count = "2" </attr>
<attr> name="firstname" val="mary" count = "1" </attr>
<attr> name="lastname" val="carlon" count = "2" </attr>

-Srini

-----Original Message-----
From: talk-bounces at xquery.com [mailto:talk-bounces at xquery.com] On Behalf
Of fatma helmy
Sent: Friday, March 03, 2006 1:21 PM
To: talk at xquery.com
Subject: [xquery-talk] how to remove repetition using distinct value
ofstrings

i have this code
let $j:=
<bookstore>
<book>
   <author firstname='joe' lastname='carlon' >
</author> 
</book>
<book>
   <author firstname='joe' lastname='carlon' >
</author> 
</book>
<book>
   <author firstname='mary' > </author> 
</book>

</bookstore>
 for $attr in  $j//author//@* 
 let $n:= name($attr) 
  
return

(
   for $v in distinct-values($j//@*[name()=$n])
return
 (
<attr>  name="{$n}" 
 val="{$v}" 
  count = "{count ($j//@*[name()= $n ] [.=$v])}"    
</attr> 

 ) 
 
 
 )

this code works but i have repetition, i need to get
distinct names of attribute list



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
talk at xquery.com
http://xquery.com/mailman/listinfo/talk



More information about the talk mailing list