Saxon Xquery Assist
A Visual Studio Code extension that runs XQuery using Saxon and passes XML and JSON input file paths as external variables.
Features
- Adds command: Run XQuery with Saxon
- Adds command: Copy XPath for Current Selection for XML editors
- Uses currently open
.xq / .xquery file, or prompts you to pick one
- Prompts for XML and/or JSON input files on every run and lets you reuse the last selected file from a quick pick
- Passes both inputs as external variables:
xmlFile=<selected XML path>
jsonFile=<selected JSON path>
- Includes a bundled Saxon HE JAR inside the VSIX package so teammates do not need to install Saxon separately
- Captures
stdout and stderr
- Saves output next to the XQuery file as
<query-name>_output.xml or <query-name>_output.txt
- Writes output to a dedicated output channel: Saxon XQuery
- Parses Saxon errors into clickable entries in the Problems panel when line and file information is available
- Optional setting to open results in a new editor tab
- Copies the XPath for the current XML element or attribute to the clipboard
- Cross-platform support for Windows, Linux, and macOS
Configuration
Open Settings and configure:
saxonRunner.saxonJarPath: optional absolute path to a custom Saxon JAR. If empty, the bundled JAR is used.
saxonRunner.openResultsInEditor: open results in a new editor tab
Example XQuery
declare variable $xmlFile external;
declare variable $jsonFile external;
let $xml := doc($xmlFile)
let $json := json-doc($jsonFile)
return (
$xml,
$json
)
Usage
- Run command: Run XQuery with Saxon
- If no XQuery file is open, select an
.xq or .xquery file
- Reuse the last XML or JSON file from the quick pick, or browse for a different one
- View results in the Saxon XQuery output channel
- Open the generated
<query-name>_output.xml or <query-name>_output.txt file beside the XQuery
XPath Helper
- Open an XML file
- Place the cursor on an element, text node, or attribute
- Run command: Copy XPath for Current Selection
- The extension copies the XPath to the clipboard and shows it in the Saxon XML XPath output channel
Development
npm install
npm run compile
Press F5 in VS Code to launch an Extension Development Host.
Packaging
npm install -g @vscode/vsce
vsce package
This generates a .vsix package you can install in VS Code.
Saxon Version In Use
- If
saxonRunner.saxonJarPath is set, that custom JAR is used.
- If
saxonRunner.saxonJarPath is empty, the bundled JAR is used from resources/saxon/saxon-he.jar.
- Bundled Saxon version is managed in
saxon.config.json.
Upgrading Bundled Saxon
- Update
version in saxon.config.json.
- Run:
npm run refresh:saxon
npm run compile
npx @vscode/vsce package
This downloads the new Saxon JAR from Maven Central, rebuilds the extension, and produces an updated VSIX.