XQuery: Simple query example -


i have assignment create xml file , query using xquery. file looks this:

<library>     <book>         <title>title1</title>         <author>author1</author>         <author>author2</author>         <subject>subject1</subject>     </book>     <book>         <title>title2</title>         <author>author3</author>         <subject>subject1</subject>     </book> </library> 

for each author, i'm supposed return title of book, title 1 should returned twice.

i've been trying this:

let $a:=doc("/home/user/library.xml")/library/book $x in $a/title, $y in $a/author return $x 

the results i'm getting are: title1 title2 title1 title2 title1 title2

i see problem every author, i'm returning every book title, i'm not sure how return book titles correspond particular author. suggestions?

thanks!

use:

   $author in distinct-values(/*/*/author)      return        /*/book[$author = author]/title/string() 

when xpath expression (that xquery, because xpath subset of xquery) evaluated against provided xml document:

<library>     <book>         <title>title1</title>         <author>author1</author>         <author>author2</author>         <subject>subject1</subject>     </book>     <book>         <title>title2</title>         <author>author3</author>         <subject>subject1</subject>     </book> </library> 

the wanted, correct result produced:

title1 title1 title2 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -