XQuery Expression to Retrieve Pages in TEI with Paragraphs Containing Keywords
✓ Published0🌍 Public
CCliffordAnderson
Last edited Mar 23, 2015
Created on Mar 23, 2015
This example demonstrates how to locate paragraphs containing a specific keyword within a TEI-encoded text and retrieve the content associated with each page based on the presence of that keyword. It first selects all `<p>` elements, filters those containing "horse," and then identifies the nearest preceding `<pb>` element to determine the page number. Using XQuery’s `fn:index-of` and positional predicates, it calculates the range of paragraphs belonging to the same page, ensuring all paragraphs on that page are returned, not just the keyword match. The code relies on XQuery 3.0, the TEI namespace, and functions like `fn:doc`, `fn:contains`, and `fn:data`, with the source document fetched from a GitHub-hosted TEI XML file.
AI-generated description