I'm trying to get the url of a publisher through an xQuery function, the function will pass the name of an author that I have in the biblio.xml document, and what I want is that given that name find the first pusblisher of a book written by that author. The information about the publisher's url is in the publist.xml file, this is the code of my function:
declare function local:getFirstPublisherUrl($aut as xs:string) as xs:string
{
for $b in doc("biblio.xml")/bib/book[author=$aut]/publisher[position()=1]
for $p in doc("publist.xml")/publist/publisher[pubname=$b]
return
if($p[puburl])then
$p/puburl/text()
else
" "
};
This is the call to my function:
<ebazpena ariketa="hamabi">
<puburlak>
{
for $aut in distinct-values(doc('biblio.xml')//author)
return
<puburl>
{ local:getFirstPublisherUrl(data($aut)) }
</puburl>
}
</puburlak>
</ebazpena>
This is my publist.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<publist>
<publisher>
<pubname>Addison-Wesley</pubname>
<pubaddress>Washington</pubaddress>
<puburl>http://www.addisonwesley.com/index.html</puburl>
</publisher>
<publisher>
<pubname>Morgan Kaufmann Publishers</pubname>
<pubaddress>New York</pubaddress>
<puburl>http://www.morgan.com/</puburl>
</publisher>
<publisher>
<pubname>Wiley</pubname>
<pubaddress>London</pubaddress>
<puburl>http://www.wiley.uk/</puburl>
</publisher>
<publisher>
<pubname>Springer-Verlag</pubname>
<pubaddress>Berlin</pubaddress>
</publisher>
</publist>
And this is the biblio.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<bib>
<book year="1994">
<title>TCP/IP Illustrated</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="1992">
<title>Advanced Programming in the Unix environment</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="2000">
<title>Data on the Web</title>
<author>
<last>Abiteboul</last>
<first>Serge</first>
</author>
<author>
<last>Buneman</last>
<first>Peter</first>
</author>
<author>
<last>Suciu</last>
<first>Dan</first>
</author>
<publisher>Morgan Kaufmann Publishers</publisher>
<price>39.95</price>
</book>
</bib>
The error is given to me in the line of the function:
for $b in doc("biblio.xml")/bib/book[author=$aut]/publisher[position()=1]
And it says the following:
A sequence of more than one item is not allowed as the result of a call to local: getFirstPublisherUrl (" link ...", " link ...")