[xquery-talk] Printing Siblings in Functions
Wei, Alice J.
ajwei at indiana.edu
Tue Mar 4 16:34:46 PST 2008
Hi, Pam:
I am not sure what you mean here, but I have just fixed my xquery now that it is working properly.
declare variable $data := fn:collection("xmldb:exist://db/cbml")//ad;
declare variable $s := $data/head[contains(upper-case(.), 'STAMP')];
declare function local:unique-nodes-by-value($seq as element()*) as
element()*
{
for $d in distinct-values($seq)
let $journal := $seq[. =$d][1]/ancestor::cbml//seriesStmt/title[@level='journal']
let $volume := $seq[. =$d][1]/ancestor::cbml//seriesStmt/idno[@type='volume']
let $issue := $seq[. =$d][1]/ancestor::cbml//seriesStmt/idno[@type='issue']
let $head2 := $seq[.=$d][1]/parent::ad/child::head
let $para := $seq[.=$d][1]/parent::ad/child::p
let $note := $seq[.=$d][1]/parent::ad/child::note
order by $d
return
<ad>
<information_source>
{$journal}
<publication>Volume {data($volume)}, Issue {data($issue)}</publication>
</information_source>
{$head2}
<description>{$para}</description>
{$note}</ad>
};
local:unique-nodes-by-value($s)
Output:
<ad>
<information_source>
<title level="journal">My Collection</title>
<publication>Volume 1 , Issue 1 </publication>
</information_source>
<head>Complimentary Collection of 50 Different U.S. Stamps</head>
<description>
<p>Receive this great Collection for only 26c mailing and handling to introduce our superb U.S. Approval sections—100 year old classics. Airmails, comments, etc. Buy any or none, return balance, cancel anytime.
<address>
<addressLine>
<emph rend="bold">Globes Stamps.</emph>
</addressLine>
<addressLine>276 Park Ave. Sq.</addressLine>
<addressLine>New York, NY. 18010.</addressLine>
</address>
</p>
</description>
<note>Dept. 323</note>
</ad>
It turns out to be some XPath expression with the number of nodes it has to be printed.
Unless you have other ideas?
Alice
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
________________________________________
From: pam clark [clarkdereon at yahoo.com]
Sent: Tuesday, March 04, 2008 4:32 PM
To: Wei, Alice J.
Subject: Re: [xquery-talk] Printing Siblings in Functions
Alice cx me from your talk query.
pc
"Wei, Alice J." <ajwei at indiana.edu> wrote:
Hi,
I have an XQuery as follows:
declare variable $data :=
High School
Diploma & Ring
YOURS Through Home Study
Prepare for GED or College Entrance
400 N. Interurban Richardson,
Texas 75080
Texts Purchased by: Departments of Education·Private
Schools·Colleges
Mail this Coupon NOW. For Persons 18 or Over
United Schools and Services Dept. M676
Box 1068, Richardson, Texas 75080
Please rush FREE information about High School
;
declare variable $s := $data/head[contains(upper-case(.),
'SCHOOL')];
declare function local:unique-nodes-by-value($seq as element()*) as
element()*
{
for $d in distinct-values($seq)
let $head := $seq/parent::ad/descendant::head
return {$head[. = $d][1]}
};
local:unique-nodes-by-value($s)
What I want to do is to extract the entire node and have it ordered by the "content within the first position of the head node,"
However, when I run the script, this is what it gives me:
High School
Diploma & Ring
My intended output is as follows:
High School
Diploma & Ring
YOURS Through Home Study
Have I done something wrong?
Any suggestion is appreciated.
Alice
======================================================
Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei at indiana.edu
_______________________________________________
talk at x-query.com
http://x-query.com/mailman/listinfo/talk
________________________________
Never miss a thing. Make Yahoo your homepage.<http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs>
More information about the talk
mailing list