Jump to content

Xquery tutorial , question


Recommended Posts

HI everybody i have done the xquery tutorial, but i have a question.in the xml document there is an book entry with more then one author,as example i have postet one example here:<book category="Test"><title lang="en">How it works</title><author>Max Mustermann</author><author>Susi Sorglos</author><author>Herbert Bauer</author></book>Now i start a query, with the following code line.for $x in doc("books.xml")/bookstore/bookreturn<name> {data($x/author)}</name>i got all the autors, but in one line,.<name>Max Mustermann Susi Sorglos Herbert Bauer</name>

 

do you have an idea to get a result like this`:

<name>Max Mustermann</name>

<name>Susi Sorglos</name>

<name>Herbert Bauer</name>

 

cheers Christian

Link to post
Share on other sites

If there's more than one author then another query is needed:

for $x in doc("books.xml")/bookstore/bookreturn {    for $y in $x/author    return <name>{data($y)}</name>}
  • Like 1
Link to post
Share on other sites

 

If there's more than one author then another query is needed:

for $x in doc("books.xml")/bookstore/bookreturn {    for $y in $x/author    return <name>{data($y)}</name>}

 

hm.. thank you men, but interresting, when i use the code with { } then i got an error message

XPST0003: Unexpected token "{" in path expression

 

i used this and now it worked, but do you have an answer to the error code?yes i know, brackets on wrong position :-)

{for $x in doc("books.xml") /bookstore/bookreturn    for $y in $x/author    return <name>{data($y)}</name>}
Edited by mchoeti
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...