0

I have the following XQUERY code in XMLSPY which runs fine.

xquery version "1.0";

<table border="1">
{
 for $re in distinct-values(reviews/review/reviewer)
 for $r in reviews/review
 where $re=$r/reviewer
 return  <tr> <td>{$r/movie_title}</td> </tr>
}
</table>

Now I want to modify it as follows :

xquery version "1.0";

<table border="1">
{
 <tr> <td>
 for $re in distinct-values(reviews/review/reviewer)
 for $r in reviews/review
 where $re=$r/reviewer
 return  {$r/movie_title}
 </td> </tr>
}
</table>

But it gives syntax error. What the second code should accomplish is that only outer for loop should create new row and new cell and inner loop should only add to that cell.

1 Answer 1

1

Try

for $re in distinct-values(reviews/review/reviewer) return <tr>{
    for $r in reviews/review
        where $re=$r/reviewer
            return <td>{$r/movie_title}</td>
}</tr>

This XMLPLayground session might help you. It does something similar, i.e. iterative table output.

Sign up to request clarification or add additional context in comments.

3 Comments

Modifying your code for what I want brought me closer to this : <table border="1"> { for $re in distinct-values(reviews/review/reviewer) return <tr><td>{ for $r in reviews/review where $re=$r/reviewer return ($r/movie_title) }</td></tr> } </table> But I want comma between each return statement
Where should I put the comma ?
Why would you want a comma between your td tags? This would lead to invalid HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.