Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Saxon.XPathQuery
Runs a XPath query.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Saxon | 15.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |
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>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 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";
"<out><person>text1</person><person>text2</person><person>text3</person></out>";
"//person[1]")
Example result: <person>text1</person>
Run with two variables:
Set Variable [ $r ; Value: MBS( "Saxon.Clear") ]
# put in the value for the variable
Set Variable [ $r ; Value: MBS( "Saxon.SetParameter"; "param"; "1"; "integer") ]
Set Variable [ $r ; Value: MBS( "Saxon.SetParameter"; "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"; "<test/>"; $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 ]
Example result: John
See also
Release notes
- Version 15.3
- Added JSON support for Saxon.XPathQuery, Saxon.XQuery and Saxon.XSLT functions.
Example Databases
Blog Entries
- JSON as input for Saxon functions
- MBS FileMaker Plugin, version 15.3pr1
- Validate electronic invoices with Saxon
- MBS FileMaker Plugin, version 15.0pr9
This function checks for a license.
Created 23th December 2024, last changed 12nd June 2025
