[xquery-talk] XPath Issues in XQuery

Wei, Alice J. ajwei at indiana.edu
Sat Feb 16 09:24:15 PST 2008


Hi, David:

  I thought you said you wanted around only 10 lines that would match the query. Since the list does not allow us to post attachments, I am pasting the 68 line complete file below:

<my>
    <myHeader>
        <fileDesc>
            <titleStmt>
                <title>My Collection</title>
            </titleStmt>
            <sourceDesc>
                <biblFull>
                    <seriesStmt>
                        <title level="journal">My Journal</title>
                        <idno type="volume"> 1 </idno>
                        <idno type="issue"> 1 </idno>
                    </seriesStmt>
                </biblFull>
            </sourceDesc>
        </fileDesc>
    </myHeader>
    <text>
        <body>
            <div>
                <ad>
                    <head>Be Taller</head>
                    <p>If you wish to know the facts about HEIGHT INCREASE, send 35c for details to
                        TALL-UP.
                        <address>
                            <addressLine>TALL-UP,</addressLine>
                            <addressLine>232 W. Front St.</addressLine>
                            <addressLine>Napoleon, Ohio 42345</addressLine>
                        </address>
                    </p>
                    <note>Dept. NA</note>
                </ad>
                <ad>
                    <head type="main">FREE POWERFUL MUSCLES FAST</head>
                    <head type="sub">FREE</head>
                    <p>Fantastic mew discoveries in the science of body-building. Our method will
                        add inches of powerful muscles to arms, chest, shoulders &amp; legs.
                        Learn secrets on trimming the waist with ultra-modern methods—fast! Results
                        guaranteed! Send for free brochure. Send dime for postage and handling.
                        <address>
                            <addressLine>Universal Bodybuilding</addressLine>
                            <addressLine>Box 485</addressLine>
                            <addressLine>Dearborn, Michigan 48121</addressLine>
                        </address>
                    </p>
                    <note>Dept. P</note>
                </ad>
            </div>
        </body>
    </text>
</my>

The Modified XQuery:

let $ad := fn:collection("xmldb:exist://db/my")
let $journal := $ad//seriesStmt/title[@level='journal'][1]
let $ad2 := $ad//ad/head[contains(upper-case(.), 'MUSCLE')]
let $sorted_result:=
for $doc in distinct-values($ad2)
order by $doc
return $doc
for $r at $count in $sorted_result
let $nodes := $ad2[. = $r][1]
return
<ad>
<statistics>
Showing Result: {$count} / {count($sorted_result)}
</statistics>
<source>
<journal>{data($journal)[1]}</journal>
<publication_information>Volume {$nodes//seriesStmt/idno[@type='volume'][1]}, Issue {$nodes//seriesStmt/idno[@type='issue'][1]}</publication_information>
</source>
{$nodes}
</ad>

I hope the relationship may be a little clearer now.
Thanks for your help.

Alice
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
________________________________________
From: David Carlisle [davidc at nag.co.uk]
Sent: Saturday, February 16, 2008 9:03 AM
To: Wei, Alice J.
Cc: talk at x-query.com
Subject: Re: [xquery-talk] XPath Issues in XQuery

> Hope this would help with the debugging.

not much.

just how difficult can it be to post a complete (small) file on which
you (and others) could run the query?

You are iterating through unique head elements that contain the word
muscle, and for each found head, you want to extract some volume
information. presumably the source file somehow indicates the
relationship between these head elements and the elements with volume
information, but without knowing what that relationship is, how can I
help?

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________



More information about the talk mailing list