[xquery-talk] Output of Following-Sibling or Preceding Sibling

Wei, Alice J. ajwei at indiana.edu
Wed Feb 20 15:16:08 PST 2008

Dear David:

   Thanks for your explanations.  It must have been my erroneous typo before with the STAMPS.  The line with $ad should have been

    let $ad2 := $ad//ad/head[contains(upper-case(.), 'MUSCLES')]

   For the $pb variable, it turned out that if I do

   let $pb := $nodes/preceding::pb[1]

from my 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(.), 'MUSCLES')]
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]
let $para := $nodes/parent::p[1]
let $head := $nodes/ancestor::ad//head[1]
let $note := $nodes/ancestor::ad//note[1]
let $seriesStmt:=$nodes/ancestor::my//seriesStmt
let $pb := $nodes/preceding::pb[1]
Showing Result: {$count} / {count($sorted_result)}
<publication_information>Volume {data($seriesStmt/idno[@type='volume'][1])},
Issue {data($seriesStmt/idno[@type='issue'][1])}</publication_information>
<information>Source from page {$pb}</information>

Brings this:

<statistics> Showing Result: 1 / 1</statistics>
<journal>My Collection</journal>
<publication_information>Volume 1 , Issue 1 </publication_information>
<head type ="main">FREE POWERFUL MUSCLES FAST</head>
<head type ="main">FREE POWERFUL MUSCLES FAST</head>
<information>Source from page
     <pb n="2" xml:id="my000110"/></information>
<note>Dept. P</note>

   This does bring the accurate pb variable that I want. However, when I only have one line of <head> in my original source, it brings back twice with the same content. When I have something like

<head type ="main">FREE POWERFUL MUSCLES FAST</head>
<head type ="sub">FREE POWERFUL MUSCLES FAST</head>

  then the above errors do not occur. I have declared that I only wanted

let $head := $nodes/ancestor::ad//head[1]

Is there something wrong with my <head> declaration here? Here is my XML again:

                <title>My Collection</title>
                        <title level="journal">My Journal</title>
                        <idno type="volume"> 1 </idno>
                        <idno type="issue"> 1 </idno>
           <pb n="1" xml:id="my000108"/>
            <pb n="2" xml:id="my000110"/>
                    <head>Be Taller</head>
                    <p>If you wish to know the facts about HEIGHT INCREASE, send 35c for details to
                            <addressLine>232 W. Front St.</addressLine>
                            <addressLine>Napoleon, Ohio 42345</addressLine>
                    <note>Dept. NA</note>
                    <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.
                            <addressLine>Universal Bodybuilding</addressLine>
                            <addressLine>Box 485</addressLine>
                            <addressLine>Dearborn, Michigan 48121</addressLine>
                    <note>Dept. P</note>
                  <pb n="3" xml:id="my000112"/>

Thanks for your help.

Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu

More information about the talk mailing list