Reputation: 453
How do I get the data to return in multiple title elements rather than one title element?
Returns this
<title>
Title 1
Title 2
Title 3
</title>
Want to return this
<title>Title 1</title>
<title>Title 2</title>
<title>Title 3</title>
Code
(: This gets coordinates from $latLon :)
let $result := for $coordinates in $latLon/location
let $lat := $coordinates/lat/text()
let $lon := $coordinates/lon/text()
(: This uses the coordinates to retrieve a title :)
let $data := titleDoc:getTitle($lat, $lon)
let $title := $data//div[@class="title"]/text()
return
<title>{$title}</title>
Upvotes: 1
Views: 132
Reputation: 735
As @chrisis says, it's hard to tell without looking at your code, but I think you want a for
instead of a let
here:
let $title := $data//div[@class="title"]/text()
return <title>{$title}</title>
The let
makes one sequence with all the text nodes, and places them in the <title>
element. That's not what you want, you want to iterate over them, creating one title element for each one:
for $title in $data//div[@class="title"]/text()
return <title>{$title}</title>
Upvotes: 3
Reputation: 1993
Difficult to answer without seeing the contents of $data. But something like this should work:
for $title in $data//div[@class="title"]
return <title>{data($title)}</title>
Upvotes: 2