[xquery-talk] XPath Issues in XQuery
Wei, Alice J.
ajwei at indiana.edu
Mon Feb 18 15:13:40 PST 2008
Hi,
I have thought about using another subject heading for this, but does not seem to be quite fit.
This is my input file:
<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 & 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>
My Current XQuery:
let $ad := fn:collection("xmldb:exist://db/cbml")
let $journal := $ad//seriesStmt/title[@level='journal'][1]
let $ad2 := $ad//ad/p/address[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]
let $para := $nodes/parent::p[1]
let $head := $nodes/parent::head[1]
let $note := $nodes/parent::note[1]
let $seriesStmt:=$nodes/ancestor::cbml//seriesStmt
let $pb := $nodes/ancestor::cbml//pb[1]
return
<ad>
<statistics>
Showing Result: {$count} / {count($sorted_result)}
</statistics>
<source>
<journal>{data($journal)[1]}</journal>
<publication_information>Volume {data($seriesStmt/idno[@type='volume'][1])},
Issue {data($seriesStmt/idno[@type='issue'][1])}</publication_information>
</source>
<head>{$head}</head>
{$nodes}
<description>{$para}</description>
<information>Source from page {$pb}</information>
<note>{$note}</note></ad>
This brings back the accurate result number, but there is no content within the <head> or <description> nodes, as shown in the following:
<ad>
<statistics> Showing Result: 1 / 1</statistics>
<source>
<journal>My Collection</journal>
<publication_information>Volume 1 , Issue 1 </publication_information>
</source>
<head/>
<address>
<addressLine>Universal Bodybuilding</addressLine>
<addressLine>Box 485</addressLine>
<addressLine>Dearborn, Michigan 48121</addressLine>
</address>
<description>
<p>Fantastic mew discoveries in the science of body-building. Our method will
add inches of powerful muscles to arms, chest, shoulders & legs.
Learn secrets on trimming the waist with ultra-modern methods—fast! Results
guaranteed! Send for free brochure. Send dime for postage and handling.
</description>
<information>Source from page
<pb n ="cover" xml:id ="etn010002-001"/>
</information>
<note/>
</ad>
The desired output:
<ad>
<statistics> Showing Result: 1 / 1</statistics>
<source>
<journal>My Collection</journal>
<publication_information>Volume 1 , Issue 1 </publication_information>
</source>
<head type="main">FREE POWERFUL MUSCLES FAST</head>
<head type="sub">FREE</head>
<address>
<addressLine>Universal Bodybuilding</addressLine>
<addressLine>Box 485</addressLine>
<addressLine>Dearborn, Michigan 48121</addressLine>
</address>
<description>
<p>Fantastic mew discoveries in the science of body-building. Our method will
add inches of powerful muscles to arms, chest, shoulders & legs.
Learn secrets on trimming the waist with ultra-modern methods—fast! Results
guaranteed! Send for free brochure. Send dime for postage and handling.
</description>
<information>Source from page
<pb n ="cover" xml:id ="etn010002-001"/>
</information>
<note>Dept. P</note>
</ad>
Any hint is appreciated.
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
More information about the talk
mailing list