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

xquery version "3.1";

declare namespace tei="";

declare variable $poem := <TEI xmlns="">
                <title>The Best Thing in the World</title>
                <author>Elizabeth Barrett Browning</author>
                <p>The Poetical Works, Vol. IV</p>
                <p>Project Gutenberg</p>
            <l>What's the best thing in the world?</l>
            <l>June-rose, by May-dew impearled;</l>
            <l>Sweet south-wind, that means no rain;</l>
            <l>Truth, not cruel to a friend;</l>
            <l>Pleasure, not in haste to end;</l>
            <l>Beauty, not self-decked and curled</l>
            <l>Till its pride is over-plain;</l>
            <l>Light, that never makes you wink;</l>
            <l>Memory, that gives no pain;</l>
            <l>Love, when, so, you're loved again.</l>
            <l>What's the best thing in the world?</l>
            <l>—Something out of it, I think.</l>

let $lines := $poem/tei:text/tei:body/tei:l
for $line in $lines
where $line contains text "Memory"