Nested queries in (X)html document

Issues related to W3C XQuery.
caraya
Posts: 1
Joined: Tue Feb 23, 2016 7:29 am

Nested queries in (X)html document

Post by caraya »

I've build the following xquery document.

Code: Select all


xquery version "3.0";
declare variable $docTitle := "Shakespeare Plays";
declare variable $docs :=
collection("file:////Users/carlos/code/xquery/shakspeare?select=*.xml");

<html>
<body>
<!-- Use $docTitle variable -->
<h1>{$docTitle}</h1>

<h2>Plays</h2>
{
for $name in $docs/PLAY/TITLE
return
<h3><a href="#{generate-id($name)}">{data($name)}</a></h3>

(: I woud like to insert the character list for each play here :)
}
<h3>Characters</h3>
<ul>
{
for $character in $docs//PERSONA
return
(<li>{data($character)}</li>)
}

</ul>
</body>
</html>
It works but not quite the way I expected it. I'm trying to insert the section beginning with <h3>Characters</h3> and the associated query inside the first query but when I put it inside I get an error: Left operand of '>' needs parenthesis.

I have not been able to find good documentation as to how to nest queries. Is this possible?

If I run the document as it is in the version above it works but not as I want it to. It generates a list names for all the plays in the collections and then it builds a complete list of all characters in all plays. Using oXygen 17.1
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Nested queries in (X)html document

Post by adrian »

Hi,

So what does the XML structure look like?

You need to nest the second query within the return of the first, for this you need a single element that surrounds everything. Maybe use a div
e.g.

Code: Select all

      for $name in $docs/PLAY/TITLE
return
<div>
<h3><a href="#{generate-id($name)}">{data($name)}</a></h3>
<h3>Characters</h3>
<ul>
{
for $character in $docs//PERSONA
return
(<li>{data($character)}</li>)
}

</ul>
</div>
My guess is you'll also need to filter the PERSONA elements depending on the PLAY/TITLE (characters for each play), but this depends on the XML structure.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply