Saxon.XQuery
------------

Runs a XML Query.

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

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

**MBS**( **"Saxon.XQuery";** /\* Runs a XML Query. \*/  
**$XML**; /\* The XML to work on. \*/   
**$Query**; /\* The query to run.  
XQuery syntax is designed to query and transform XML data using FLWOR expressions—For, Let, Where, Order by, and Return. It allows variables (prefixed with $), path expressions (like XPath), conditional logic (if, where), and supports functions to manipulate XML or return results in various formats. XQuery builds on XPath, so all XPath expressions are valid inside XQuery. \*/   
**$Namespaces**) /\* Optional; The list of namespaces to declare in the style Key=URL. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| XML | The XML to work on. |  |  |
| Query | The query to run.   XQuery syntax is designed to query and transform XML data using FLWOR expressions—For, Let, Where, Order by, and Return. It allows variables (prefixed with $), path expressions (like XPath), conditional logic (if, where), and supports functions to manipulate XML or return results in various formats. XQuery builds on XPath, so all XPath expressions are valid inside XQuery. |  |  |
| Namespaces | The list of namespaces to declare in the style Key=URL. |  | Optional      Added in version **15.1**. |

### Result

Returns XML or error.

### Description

Runs a XML Query.  
XQuery is a powerful query language designed to extract and manipulate data from XML documents. It can perform complex operations such as filtering, joining, and transforming XML data much like SQL does for relational databases.  
  
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.  
The query BaseURI can be set with [Saxon.SetBaseURI](SaxonSetBaseURI.md) function.  
  
XQuery includes:  
  
- XQuery 3.1 Minimal Conformance: Provides Minimal Conformance (including try/catch and "group-by", as well as language features retained from earlier XQuery versions) as defined in section 5 of the XQuery 3.1 specification.
- XQuery 3.1 Modules: Provides the Module feature, which allows a query to be made up of multiple modules.
- XQuery 3.1 Serialization: Provides the Serialization feature. This allows the output of a query to be serialized as lexical XML, or in other formats including HTML, JSON, and plain text, under the control of serialization parameters contained either in the query itself, or supplied externally.
- XQuery 3.1 Higher-Order: Provides the Higher-Order Function feature. This provides 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.
- Streaming with EE license: Provides saxon:stream(), an extension function to allow large documents to be processed without holding the whole document in memory.

### Examples

Try a query:

 Let(\[  
xml = "&lt;?xml version=\\"1.0 \\" encoding=\\"UTF-8\\"?&gt;  
&lt;people&gt;  
 &lt;person dept=\\"sales\\"&gt;  
 &lt;name&gt; mary&lt;/name&gt;  
 &lt;age&gt;20&lt;/age&gt;  
 &lt;/person&gt;  
 &lt;person dept=\\"marketing\\"&gt;  
 &lt;name&gt;cindy&lt;/name&gt;  
 &lt;age&gt;25&lt;/age&gt;  
 &lt;/person&gt;  
 &lt;person dept=\\"sales\\"&gt;  
 &lt;name&gt;john&lt;/name&gt;  
 &lt;age&gt;40&lt;/age&gt;  
 &lt;/person&gt;  
 &lt;person dept=\\"accounting\\"&gt;  
 &lt;name&gt;peter&lt;/name&gt;  
 &lt;age&gt;35&lt;/age&gt;  
 &lt;/person&gt;  
&lt;/people&gt;";  
query = "for $i in /people/person¶  
where $i /age &gt; 30¶  
return data($i /name)";  
r = MBS ( "Saxon.XQuery"; xml; query )  
\]; r)  
<small>  
Example result: &lt;?xml version="1.0" encoding="UTF-8"?&gt;john peter</small>Try with JSON:

 Set Variable \[ $r ; Value: MBS ( "Saxon.XQuery"; "{ \\"name\\": \\"John\\", \\"age\\": 30, \\"city\\": \\"New York\\" }"; "&lt;p&gt;{ data(?name) }&lt;/p&gt;" ) \]  
Set Field \[ Saxon XSLT::Result ; $r \]  
### See also

- [Saxon.SetBaseURI](SaxonSetBaseURI.md)
- [Saxon.SetLanguageVersion](SaxonSetLanguageVersion.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 XQuery MrWatsons Examples](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XQuery%20MrWatsons%20Examples.shtml#2ScriptAnchor_)
- [Saxon/Saxon XQuery](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Saxon/Saxon%20XQuery.shtml#2ScriptAnchor_)

### Blog Entries

- [Elektronische Rechnungen in FileMaker mit dem MBS Plugin lokal erzeugen](https://www.mbsplugins.de/archive/2026-09-12/Elektronische_Rechnungen_in_Fi/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)

This function checks for a license.

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

  
[Saxon.XPathQuery](SaxonXPathQuery.md) - [Saxon.XSLT](SaxonXSLT.md)

[HTML Version](SaxonXQuery.shtml)