#  TC/MD_Q1 Return the title of the article that has matching id attribute value (1).

for $art in input()/article[@id="1"]
return
    $art/prolog/title


# TC/MD_Q2 Find the title of the article authored by (Ben Yang).

for $prolog in input()/article/prolog
where
    $prolog/authors/author/name="Ben Yang"
return
    $prolog/title


# TC/MD_Q3 Group articles by date and calculate the total number of articles in each group.

for $a in distinct-values (input()/article/prolog/dateline/date)
let $b := input()/article/prolog/dateline[date=$a]
return
    <Output>
        <Date>{$a/text()}</Date>
        <NumberOfArticles>{count($b)}</NumberOfArticles>
    </Output>

# TC/MD_Q4 Find the heading of the section following the section entitled ``Introduction" in a certain article with id attribute value (8).

for $a in input()/article[@id="8"]/body/section
    [@heading="introduction"],
    $p in input()/article[@id="8"]/body/section
    [. >> $a][1]
return
    <HeadingOfSection>
        {$p/@heading}
    </HeadingOfSection>

# TC/MD_Q5 Return the headings of the first section of a certain article with id attribute value (9).

for $a in input()/article[@id="9"]
return
    <HeadingOfSection>
        {$a/body/section[1]/@heading}
    </HeadingOfSection>

# TC/MD_Q6 Find titles of articles where both keywords (``the" and ``hockey") are mentioned in the same paragraph of abstracts.

for $a in input()/article
where some $b in $a/body/abstract/p satisfies
    (contains($b, "the") and contains($b, "hockey"))
return
    $a/prolog/title


# TC/MD_Q7 Find titles of articles where a keyword (``hockey") is mentioned in every paragraph of abstract.

for $a in input()/article
where every $b in $a/body/abstract/p satisfies
    contains($b, "hockey")
return
    $a/prolog/title


# TC/MD_Q8 Return the names of all authors (one element name unknown) of the article with matching id attribute value (2).

for $art in input()/article[@id="2"]
return
    $art/prolog/*/author/name


# TC/MD_Q9 Return all author names (several consecutive element unknown) of the article with matching id attribute value (3).

for $art in input()/article[@id="3"]
return
    $art//author/name


# TC/MD_Q10 List the titles of articles sorted by country.

for $a in input()/article/prolog
order by $a/dateline/country
return
    <Output>
        {$a/title}
        {$a/dateline/country}
    </Output>

# TC/MD_Q11 List the titles of articles that have a matching country element type (Canada), sorted by date.

for $a in input()/article/prolog
where $a/dateline/country="Canada"
order by $a/dateline/date
return
    <Output>
        {$a/title}
        {$a/dateline/date}
    </Output>

# TC/MD_Q12 Retrieve the body of the article that has a matching id attribute value (4).

for $a in input()/article[@id="4"]
return
    <Article>
        {$a/body}
    </Article>

# TC/MD_Q13 Construct a brief information on the article that has a matching id attribute value (5), including title, the name of first author, date and abstract.

for $a in input()/article[@id="5"]
return
    <Output>
        {$a/prolog/title}
        {$a/prolog/authors/author[1]/name}
        {$a/prolog/dateline/date}
        {$a/body/abstract}
    </Output>

# TC/MD_Q14 List article title that doesn't have genre element.

for $a in input()/article/prolog
where empty ($a/genre)
return
    <NoGenre>
        {$a/title}
    </NoGenre>

# TC/MD_Q15 List author names whose contact elements are empty in articles.

for $a in input()/article/prolog/authors/author
where empty($a/contact/text())
return
    <NoContact>
        {$a/name}
    </NoContact>

# TC/MD_Q16 Get the article by its id attribute value (6).

for $a in input()/article[@id="6"]
return
    $a


# TC/MD_Q17 Return the titles of articles which contain a certain word (``hockey").

for $a in input()/article
where contains ($a//p, "hockey")
return
    $a/prolog/title


# TC/MD_Q18 List the titles and abstracts of articles which contain a given phrase (``the hockey").

for $a in input()/article
where contains ($a//p, "the hockey")
return
    <Output>
        {$a/prolog/title}
        {$a/body/abstract}
    </Output>

# TC/MD_Q19 List the names of articles cited by an article with a certain id attribute value (7).

for $a in input()/article[@id='7']/epilog/references/a_id,
    $b in input()/article
where $a = $b/@id
return
    <Output>
        {$b/prolog/title}
    </Output>

