This code sample is adapted from Clifford B. Anderson and Joseph C. Wicentowski, XQuery for Humanists (College Station: Texas A&M University Press, 2020), 77. Download this code sample in its raw form. View the source on GitHub.

xquery version "3.1";

declare context item := document {
    <title>Primo Levi: The Matter of a Life</title>
    <author>Berel Lang</author>
    <date year="2013">November 26, 2013</date>
        <city>New Haven</city>
        <press>Yale University Press</press>
    <identifier type="ISBN-10">0300137230</identifier>
    <identifier type="ISBN-13">978-0300137231</identifier>

/descendant-or-self::press[self::node() = "Yale University Press"]/parent::publisher/preceding-sibling::title/text()