Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following XPath queries on the “inventory.xml” to select: a) All award

ID: 3861506 • Letter: W

Question

Write the following XPath queries on the “inventory.xml” to select:

a) All award elements in the document.

b) The author(s) of the last book element

c) All magazine elements whose style attribute value is equal to glossy value of the bookstore element at the root of the document.

d) All award elements that belong to book elements that have an id attribute.

e) All title elements one or more levels deep in the element.

f) All price elements elements of the book elements.

g) All author elements of books whose prices is less than 30 or greater than 50.

h) All magazine elements with style attributes.

XML Document:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="myfile.xsl" ?>
<bookstore specialty="novel">
<book>
<author>
<first-name>Joe</first-name>
<last-name>Bob</last-name>
<award>Trenton Literary Review Honorable Mention</award>
</author>
<price>12</price>
</book>
<book>
<author>
<first-name>Mary</first-name>
<last-name>Bob</last-name>
<publication>Selected Short Stories</publication>
</author>
<editor>
<first-name>Britney</first-name>
<last-name>Bob</last-name>
</editor>
<price>55</price>
</book>
<magazine frequency="monthly">
<price>2.50</price>
<subscription price="24" per="year"/>
</magazine>
<book id="myfave">
<author>
<first-name>Toni</first-name>
<last-name>Bob</last-name>
<degree from="Trenton U">B.A.</degree>
<degree from="Harvard">Ph.D.</degree>
<award>Pulitzer</award>
<publication>Still in Trenton</publication>
<publication>Trenton Forever</publication>
</author>
<price intl="Canada" exchange="0.7">6.50</price>
<excerpt>
<p>It was a dark and stormy night.</p>
<p>But then all nights in Trenton seem dark and
stormy to someone who has gone through what
<emph>I</emph> have.</p>
<definition-list>
<term>Trenton</term>
<definition>misery</definition>
</definition-list>
</excerpt>
</book>
<my:book xmlns:my="uri:mynamespace" price="29.50">
<my:title>Who's Who in Trenton</my:title>
<my:author>Robert Bob</my:author>
</my:book>
</bookstore>

Explanation / Answer

1) All award element

Bookstore/Book/author/award

2)   The author(s) of the last book element

/bookstore/book[last()]/author/award

3)   All magazine elements whose style attribute value is equal to glossy value of the bookstore element at the root of the document.

/bookstore/book/magazine/@style='glosy'

4) All award elements that belong to book elements that have an id attribute.

/Bookstore/book[@id]/author/award

5) All title elements one or more levels deep in the element.

6) All price elements elements of the book elements.

  bookstore/book/price

7) All author elements of books whose prices is less than 30 or greater than 50.

  Bookstore/Book[price> 30 or price <80]/author

8) All magazine elements with style attributes.

/bookstore/book/magazine[@style='glosy']