database - how to count the number of occurrences of a particular attribute in an xml file? -


given following xml file, need report uid of user has less 4 followers , uid of followers.

<!doctype users system "users.dtd"> <users>  <user uid = "u1" dob = "06/03/94" email = "tom@hotmail.com">     <surname> doe</surname>     <givennames> jon </givennames>     <follows = "u1 u2"/>     <playlists>       <playlist pid = "p1" created ="12/03/11" playcount = "5" />      </playlists>    </user>    <user uid = "u2" dob = "06/03/95" email = "jane@hotmail.com">     <surname> dod</surname>     <givennames> jane </givennames>     <follows = "u1 u3"/>     <playlists>       <playlist pid = "p2" created ="12/02/10" playcount = "2"/>      </playlists>    </user>     <user uid = "u3" dob = "06/04/95" email = "dave@hotmail.com">     <surname> ron</surname>     <givennames> dave </givennames>     <follows = "u1 u2"/>     <playlists>       <playlist pid = "p3" created ="12/02/09" playcount = "9"/>       </playlists>    </user>     <user uid = "u4" dob = "06/04/99" email = "jeff@hotmail.com">     <surname> dun</surname>     <givennames> jeff</givennames>      <follows = "u1 u2 u3"/>     <playlists>       <playlist pid = "p4" created ="12/02/09" playcount = "3"/>      </playlists>    </user>  </users> 

i need query gives output:

<fewfollowers>     <who uid = "u2">            <follower uid = "u1"/>            <follower uid = "u3"/>            <follower uid = "u4"/>     </who>     <who uid = "u3">            <follower uid = "u2"/>            <follower uid = "u4"/>     </who>     <who uid = "u4">     </who> </fewfollowers> 

!attlist follows idrefs #implied

if user reported doesn't have followers, report own uid

i've tried utilizing count() function i'm not getting helpful. try:

for $user in doc("users.xml")/users/user    return count($user/follows/@who = $user") 

but seems return count of @who each $user , not particular element. furthermore, how traverse through idrefs attribute? they're supposed distinguished white space count function seems register 1 attribute instead of multiple. had expected function return atleast:

 1, 2, 2, 3 

but returns:

1,1,1,1 

assuming dtd defines @who type idrefs, , @uid type id, should able things like

let $followers := idref($user/follows/@who) return (count($followers) || string-join($followers/email, "; ") 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -