untitled

(ff) #1
387

Alternatively, one can use the XQuery function that extracts the year from
a date as in the following query:

document("healthstudy.xml")
//Interview[year-from-dateTime(@Date)=2000 and @BMI>30]
ANSWER TO
EXERCISE8.2
First find the insulin gene locus. Then within this locus find all literature
entries. An entry is a literature reference if the reference element containing
the entry is named “Literature references.” Note the use of “..”toobtain
the name attribute of the parent element of the entry.


for $locus in document("bio.xml")//locus
where $locus/gene/@name = "Insulin gene"
return (for $entry in $locus/reference/db_entry
where $entry/../@name = "Literature references"
return $entry)
ANSWER TO
EXERCISE8.3
Look for all citations that have a MeSH heading satisfying the criteria. The
following query looks at all citations, and then within each citation it looks
at every heading. Whenever a heading satisfies the criteria, the citation is
returned.


for $citation in
document("pubmed.xml")//MedlineCitation,
$heading in
$citation//MeshHeading
where $heading/DescriptorName/@MajorTopicYN="Y"
and $heading/DescriptorName="Glutethimide"
and $heading/QualifierName="therapeutic use"
return $citation

In the query above, if a citation has more than one MeSH heading that
satisfies the criteria, then the citation will be returned more than once. One
can avoid this problem by using a “nested” subquery as in the following
query. For each citation, this query runs a separate subsidiary query that
finds all headings within the citation that satisfy the criteria. If the nested
subquery has one or more results, then the citation is returned.
Free download pdf