[xquery-talk] Query Through Multiple Files
John Snelson
john.snelson at oracle.com
Tue Jan 22 15:15:46 PST 2008
Hi Alice,
You basically have a grouping problem to solve, which can be done like this:
let $addresses := (doc("1.xml") | doc("3.xml") |
doc("4.xml") | doc("2.xml"))//ad/p/address
let $sorted_result:=
for $doc in distinct-values($addresses)
order by $doc ascending
return $doc
for $r at $count in $sorted_result
let $nodes := $addresses[. = $r]
return
<bibl>
<statistics>
Showing Result: {$count} / {count($sorted_result)}
</statistics>
{$nodes}
</bibl>
John
Wei, Alice J. wrote:
> Hi, Michael:
>
>
>
> Sorry, but that is not entirely what I want. I was hoping to not just
> keep the information but also the markup. Is there some way I can do that?
>
> This means that I should not be using distinct-values() because it is
> similar to <xsl:value-of select=""> as in XSLT, right?
>
>
>
> Here is the code again:
>
>
>
> declare boundary-space preserve;
>
>
>
> <book>
>
> {
>
> let $sorted_result:= for $doc in
>
> distinct-values((doc("1.xml"),doc("3.xml"),
>
> doc("4.xml"), doc("2.xml"))//ad/p/address)
>
> order by $doc ascending
>
> return $doc
>
> for $sorted_results at $count in $sorted_result
>
> return
>
> <bibl>
>
> <statistics>Showing Result: {$count} / {count($sorted_result)}
>
> </statistics>
>
> {$sorted_result}
>
> </bibl>
>
> }
>
> </book>
>
>
>
> Thanks for your help.
>
>
>
> ======================================================
>
> Alice Wei
>
> MIS 2008
>
> School of Library and Information Science
>
> Indiana University Bloomington
>
> ajwei at indiana.edu <mailto:ajwei at indiana.edu>
>
>
>
> -----Original Message-----
> From: Michael Kay [mailto:mike at saxonica.com]
> Sent: Monday, January 21, 2008 4:04 PM
> To: Wei, Alice J.; 'Liam Quin'
> Cc: talk at x-query.com
> Subject: RE: [xquery-talk] Query Through Multiple Files
>
>
>
>
>
>
>
> > I tried using
>
> > distinct-values(doc("1.xml"), doc("3.xml"), doc("4.xml"),
>
> > doc("2.xml"))//title, but I got the error that there should
>
> > be only 2 arguments.
>
>
>
> You didn't read my example carefully enough
>
>
>
> distinct-values(( doc("1.xml"),
>
> doc("2.xml"),
>
> doc("3.xml"),
>
> doc("4.xml"))//ad)
>
>
>
> Firstly, you want to find the set of titles and then take the distinct
>
> values in this set: so the "//title" part needs to inside the argument to
>
> distinct-values(). The way you've written it, you're taking four documents,
>
> then eliminating duplicates, then taking the title elements within those
>
> that are left.
>
>
>
> Secondly, if you supply a sequence to a function that expects a single
>
> argument then you need to double the parentheses, for example
>
> sum((1,2,3,4,5)) or distinct-values((1,2,2,4,4)). That's to make it clear
>
> you are passing one argument which is a sequence of five integers, not five
>
> arguments that are single integers. IN your case you've called
>
> distinct-values() with four arguments, rather than with a single argument
>
> that is a sequence.
>
>
>
> Michael Kay
>
> http://www.saxonica.com/
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
--
John Snelson, Oracle Corporation http://snelson.org.uk/john
Berkeley DB XML: http://www.oracle.com/database/berkeley-db/xml
XQilla: http://xqilla.sourceforge.net
More information about the talk
mailing list