FILTERXML Function (LibreOffice Calc)
Query local XML with LibreOffice FILTERXML. Distinguish text nodes, numeric XPath results and scalar selection, with a complete small document to reproduce.
Verification status: 9 source-derived examples were checked against LibreOffice 26.8 Help and the complete 26.8.1.1 callback. The fixed ASCII XML examples were independently evaluated locally; no LibreOffice execution or external resource access. How formula examples are checked
Quick answer: With the complete XML text below in A1, FILTERXML(A1;"/catalog/item[1]/name") selects Pen. A node selection returns its text; a numeric XPath expression follows a separate numeric branch.
Availability and version history
- Introduced: LibreOffice 4.2, explicitly stated in function-specific Help.
- Supported in: 26.8 Help and 26.8.1.1 registration; no retirement is established.
- Scope: Desktop Calc, English formulas. The documented
COM.MICROSOFT.FILTERXMLnamespace is outside OpenFormula 1.3. - Checked: October 14, 2026. Documentation and the complete callback were inspected. Local ASCII XPath references were independently checked; no LibreOffice parser or GUI run is claimed.
What FILTERXML does
FILTERXML applies an XPath expression to XML supplied as text. The XML does not have to come from a web request: a fixed local document makes a clearer example and separates parsing from external-link behavior. A displayed web page or arbitrary JSON response is not automatically a valid XML document.
The inspected implementation passes the document and expression to its XML/XPath library, then handles node sets, numbers, strings and Booleans separately. The examples use ordinary ASCII XML without external resources, document-type declarations or custom entities. Independent local XPath checks are mathematical/parser reference checks, not LibreOffice execution. Function Help.
Syntax and arguments
FILTERXML(XMLDocument; XPathExpression)
Both arguments are required strings. XMLDocument contains the complete XML text; XPathExpression describes the selection or calculation. Store the document in A1 to avoid repeatedly escaping its attribute quotation marks inside a formula. The XPath examples use one-based item positions, and their attribute names and element names match the document’s case.
Source-derived examples
These results use the fixed document below and independent local XPath evaluation. They are not recorded LibreOffice outputs.
Put this exact text in A1 as cell text, not as a formula:
<catalog><item code="A"><name>Pen</name><price>2.50</price></item><item code="B"><name>Book</name><price>12</price></item></catalog>
| Formula | Source-derived result or interpretation | Context |
|---|---|---|
=FILTERXML(A1;"/catalog/item[1]/name") |
Pen (text) | The first item’s name. |
=FILTERXML(A1;"/catalog/item[2]/@code") |
B (text) | An attribute node supplies its content. |
=FILTERXML(A1;"/catalog/item[1]/price") |
2.50 (text) | Selecting the node preserves its text representation. |
=FILTERXML(A1;"number(/catalog/item[1]/price)") |
2.5 (number) | The XPath number function requests numerical conversion. |
=FILTERXML(A1;"count(/catalog/item)") |
2 (number) | Count the item elements. |
=FILTERXML(A1;"sum(/catalog/item/price)") |
14.5 (number) | Add the two numeric price texts in XPath. |
=FILTERXML(A1;"boolean(/catalog/item[price>10])") |
1 (number) | The Boolean XPath result is pushed as numeric 1 in the inspected callback. |
=FILTERXML(A1;"concat(/catalog/item[1]/name,' + ',/catalog/item[2]/name)") |
Pen + Book (text) | An ASCII XPath string result. |
=FILTERXML(A1;"/catalog/item/name") |
Pen (text, scalar context) | The inspected ordinary scalar path selects the first matching node. |
Practical worksheet
For a compact audit of the fixed document, put =FILTERXML(A1;"count(/catalog/item)") in B1 and =FILTERXML(A1;"sum(/catalog/item/price)") in B2. Their independently checked results are 2 and 14.5. If you expect exactly two items, inspect the count before treating the sum as a complete total.
Keep a copy of the document used for an analysis. A later change from two items to three changes the meaning of both checks. This is a source-data issue rather than an arithmetic error. The example uses literal XML text and requires no WEBSERVICE call or external connection.
Advanced interpretation and checks
A node-set expression can match several nodes. The scalar path shown here returns only the first selected node. In a matrix context, the callback can produce a one-column result sized from the calculation context and fills unavailable extra positions with not-available errors. That does not prove automatic spilling or a particular GUI array-entry procedure. Use explicit item positions for a predictable single value.
Distinguish missing nodes from empty strings: selecting a nonexistent node follows a not-available branch, whereas a valid XPath string expression can return empty text. Numeric conversion and Boolean expressions also have their own branches. For non-ASCII string-producing XPath expressions, additional encoding checks are needed: the inspected string-result branch uses an ASCII conversion, while node content uses UTF-8 conversion. This guide’s string-expression example deliberately stays ASCII. Inspected implementation.
Boundaries and troubleshooting
Empty XML or XPath, a failed XML parse, or a failed XPath evaluation follows the no-value error path in the inspected source. No malformed document or external-resource behavior was executed. Namespace-prefixed queries require context beyond the simple namespace-free document used here; this guide does not promise automatic namespace binding.
Array entry, large documents, parser-version differences and GUI error displays remain untested. If you later combine FILTERXML with an external request, first inspect and preserve the returned text independently. A network or permission failure must not be mistaken for evidence that the XPath expression is wrong.
Related functions
WEBSERVICE, VALUE, LEN.
Official evidence and checking scope
The inspected version is LibreOffice 26.8.1.1 source; it was not executed. Independent XPath checks used the supplied local document with external resources disabled; no LibreOffice array-entry, namespace or Unicode-string behavior was certified.