[xquery-talk] leaf values

Michael Kay mhk at mhk.me.uk
Sat Feb 11 21:28:41 PST 2006

I'm not sure what you mean when you say that $p contains three "paths".
XQuery variables contain values, which are sequences of nodes and atomic
values: a path is neither a node nor an atomic value.

Your term "leaf" is also a term that's not used in the XQuery data model.
You appear to be using it to mean "an element that has no elements among its
children". But the term could have other meanings, for example "an element
whose type is a simple type" - which isn't the same thing, because we can't
tell from this instance whether or not title is allowed (by the schema) to
have child elements.

Your output is also unclear because the start tags don't match the end tags
(in fact, they aren't proper XML at all).

Perhaps you want something like this:

let $b := book
for $p in ("title", "price")
<path path="book/{$p}">{
  for $d in distinct-values($b/*[name()=$p])
    <value-per-path value="{$d}" count="count($b/*[name()=$p][.=$d])"/>

But I'm still unclear what you mean about "leaf values".

Michael Kay

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of fatma helmy
> Sent: 11 February 2006 17:02
> To: talk at xquery.com
> Subject: [xquery-talk] leaf values
> Suppose I have the following xml
> <book >
> 	<title>seven years in trenton</title>
> 	<price>12</price>
> </book>
> <book >
> 	<title> history of trenton</title>
> 	<price> 55</price>
> </book>
> <book >
> 	<title> trenton today, trenton tomorrow	</title>	
> 	<price> 55</price>
>         <author> </author>
> </book>
> </bookstore>
> suppose also , I have $p which contains the following
> paths book/title , book/price,book/author. since title
> and price are leaves and have values ,  I need for $I
> in $p < select values of leaves nodes> such that the
> result would be for example
> < path= "book/price " >
> <value- per-path  value="12" count="1" />
> <value -per-path  value="55" count="2" />
> </attr-per-path>
> < path= "book/title" >
> <value- per-path  value=" seven years in trenton "
> count="1" />
> <value -per-path  value=" history of trenton "
> count="1" />
> <value -per-path  value=" trenton today, trenton
> tomorrow " count="1" />
> </attr-per-path>
>  I need this to be done for leaves only which contain
> the data.
> __________________________________________________
> 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