Saxon.XPathQuery
----------------

Runs a XPath query.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Saxon](component_Saxon.md) | [15.0](newinversion150.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |

MBS( "Saxon.XPathQuery"; XML; Query { ; Namespaces; VariableList } ) 

**MBS**( **"Saxon.XPathQuery";** /\* Runs a XPath query. \*/  
**$XML**; /\* The XML to work on. \*/   
**$Query**; /\* The query to run.  
XPath query syntax uses path-like expressions to navigate through elements and attributes in an XML document. It starts with / for absolute paths (from the root) or // for relative paths (anywhere in the document). Nodes are selected by names (e.g., /bookstore/book), and filters can be applied using square brackets (e.g., //book\[price&gt;30\]). You can also use @ to select attributes (e.g., //book\[@category='fiction'\]) and functions like text(), contains(), or position() to refine queries. \*/   
**$Namespaces**; /\* Optional; The list of namespaces to declare in the style Key=URL. \*/   
**$VariableList**) /\* Optional; List of parameters to become variables. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| XML | The XML to work on. |  |  |
| Query | The query to run.   XPath query syntax uses path-like expressions to navigate through elements and attributes in an XML document. It starts with / for absolute paths (from the root) or // for relative paths (anywhere in the document). Nodes are selected by names (e.g., /bookstore/book), and filters can be applied using square brackets (e.g., //book\[price&gt;30\]). You can also use @ to select attributes (e.g., //book\[@category='fiction'\]) and functions like text(), contains(), or position() to refine queries. |  |  |
| Namespaces | The list of namespaces to declare in the style Key=URL. |  | Optional      Added in version **15.1**. |
| VariableList | List of parameters to become variables. |  | Optional |

### Result

Returns XML or error.

### Description

Runs a XPath query.  
XPathQuery (commonly called XPath) is a language used to navigate and select nodes from an XML document using path-like expressions. It's often used within XSLT, XQuery, and XML-processing tools to pinpoint data locations efficiently.  
  
You can set the language version with [Saxon.SetLanguageVersion](SaxonSetLanguageVersion.md) function.  
Set the current working directory with Saxon.SetCWD function, so the function can find relative files.  
  
XPath 3.1 Basic  
  
Provides all XPath 3.1 features which do not require schema-awareness or higher-order functions. This includes an implementation of maps and arrays, and support for JSON, as well as language constructs retained from earlier XPath versions.  
  
XPath 3.1 Higher-Order  
  
Provides higher-order functions: specifically, the ability to use functions as values, including dynamic function calls, inline functions, partial function application, and a library of built-in higher-order functions.  
  
XPath 3.1 Schema Aware with EE-V license  
  
Provides schema-awareness: specifically, any use of source documents with type annotations, and any use of XPath expressions that contain the names of schema components such as element declarations and types, other than the built-in types.  
### Examples

Run query:

 MBS ("Saxon.XPathQuery";   
"&lt;out&gt;&lt;person&gt;text1&lt;/person&gt;&lt;person&gt;text2&lt;/person&gt;&lt;person&gt;text3&lt;/person&gt;&lt;/out&gt;";   
"//person\[1\]")  
<small>  
Example result: &lt;person&gt;text1&lt;/person&gt;</small>Run with two variables:

 Set Variable \[ $r ; Value: MBS ( "[Saxon.Clear](SaxonClear.md)") \]  
\# put in the value for the variable   
Set Variable \[ $r ; Value: MBS ( "[Saxon.SetParameter](SaxonSetParameter.md)"; "param"; "1"; "integer") \]  
Set Variable \[ $r ; Value: MBS ( "[Saxon.SetParameter](SaxonSetParameter.md)"; "other"; "2.4 "; "json") \]  
\# now run a query and pass list of variables   
Set Variable \[ $query ; Value: "$param +$other " \]  
Set Variable \[ $VariableList ; Value: "param¶other" \]  
Set Variable \[ $r ; Value: MBS ( "Saxon.XPathQuery"; "&lt;test/&gt;"; $Query ; $VariableList ) \]  
Set Field \[ Saxon XSLT::Result ; $r \]  
Try with JSON:

 Set Variable \[ $r ; Value: MBS ( "Saxon.XPathQuery"; "{ \\"name\\": \\"John\\", \\"age\\": 30, \\"city\\": \\"New York\\" }"; "?name" ) \]  
Set Field \[ Saxon XSLT::Result ; $r \]  
<small>  
Example result: John</small>### See also

- [Saxon.Clear](SaxonClear.md)
- [Saxon.SetLanguageVersion](SaxonSetLanguageVersion.md)
- [Saxon.SetParameter](SaxonSetParameter.md)

### Release notes

- **Version 15.3**
    - Added JSON support for [Saxon.XPathQuery](https://www.mbsplugins.eu/SaxonXPathQuery.shtml), [Saxon.XQuery](https://www.mbsplugins.eu/SaxonXQuery.shtml) and [Saxon.XSLT](https://www.mbsplugins.eu/SaxonXSLT.shtml) functions.

### Example Databases

- [Saxon/Saxon XPath](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XPath.shtml#2ScriptAnchor_)

### Blog Entries

- [Validate electronic invoices with Saxon](https://www.mbsplugins.de/archive/2026-03-20/Validate_electronic_invoices_w/monkeybreadsoftware_blog_filemaker)
- [Use Saxon to query details from FileMaker's Save as XML files](https://www.mbsplugins.de/archive/2026-01-28/Use_Saxon_to_query_details_fro/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 15.3 für Claris FileMaker](https://www.mbsplugins.de/archive/2025-07-15/Neues_MBS_Plugin_153_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 15.3 for Claris FileMaker](https://www.mbsplugins.de/archive/2025-07-15/MBS_Plugin_153_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [JSON as input for Saxon functions](https://www.mbsplugins.de/archive/2025-06-13/JSON_as_input_for_Saxon_functi/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.3pr1](https://www.mbsplugins.de/archive/2025-06-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Validate electronic invoices with Saxon](https://www.mbsplugins.de/archive/2025-02-18/Validate_electronic_invoices_w/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 15.0pr9](https://www.mbsplugins.de/archive/2025-01-10/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 23th December 2024 , last changed 12nd June 2025

  
[Saxon.Version](SaxonVersion.md) - [Saxon.XQuery](SaxonXQuery.md)

[HTML Version](SaxonXPathQuery.shtml)