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

let $documents :=
        <title>The Secretary of State to the Consul at Taipei (Edgar)</title>
        <body>88. Urtel 150 May 6. Dept notes ur statement "question being asked
            locally" etc. Pls identify persons raising this question.</body>
        <title>The Ambassador in China (Stuart) to the Secretary of
        <body>539. Col. Dau returned from Taipei (Embtel 500, Mar. 9) Mar. 11
            and his view situation telegraphed War Department with request
            information be transmitted to State Department.</body>
let $query-term := "Taipei"
for $document score $score in $documents/document
        title contains text ({$query-term} weight {10})
        body contains text ({$query-term})
order by $score descending
    <hit score="{ fn:format-number($score, '0.00') }">{