XSLT and XPath

for Visual Studio Code

143K Installs:

AI Assistants

AI coding assistants in Visual Studio Code - such as GitHub Copilot or Claude Code - can make good use of the XSLT/XPath extension. Most of what they use needs nothing special from it: the extension's problems, documentation notes and debugging output are all in forms that assistants read and write well. For more, the extension has an MCP server, so an assistant can ask it directly - for example, for the problems of a stylesheet that isn't open, or where a function is declared.

Fixing problems

The problems reported by the extension's linter are standard Visual Studio Code diagnostics, shown in the Problems view. They identify the exact symbol at issue - an unresolved variable, a function called with the wrong number of arguments, a record field that doesn't exist - so an assistant that reads the diagnostics can explain and fix them precisely, and check its own changes the same way. For example, GitHub Copilot can include the problems with #problems in a chat prompt, or fix a problem from its Quick Fix menu, and Claude Code reads them through its Visual Studio Code integration.

The problems are kept up to date for every stylesheet open in an editor - not only the active one. An assistant usually changes files while your cursor is in another, so a stylesheet it changes is checked again, whether it's shown beside the active editor or in a tab that isn't shown, and the assistant sees the problems its change caused. When it changes several stylesheets at once, each is checked with its own declarations, XSLT version and imports, so no problems are reported that aren't there.

The MCP server (experimental)

The extension can run a Model Context Protocol (MCP) server, with tools an assistant can call to ask the extension about your stylesheets. The tools use the same code as the editor - the linter, Go to Definition, Find All References and the XSLT Imports view - so their answers match what you see, and they work for files that aren't open. The server is off by default: to turn it on, set XSLT.mcp.enabled to true - see Settings.

Tool What it gives the assistant
lint_file The problems in an XSLT module or XSpec file - as the Problems view shows them, checked with its imports, includes and packages - whether or not it's open. Optionally, only those of a severity or worse.
lint_files The problems in each XSLT and XSpec file in a folder: a summary, then only the files with problems. By default, warnings and errors - not hints, such as unused variables.
module_imports The tree of imports, includes and packages from a module's top-level stylesheet down, with the module marked - as in the XSLT Imports view.
find_declaration Where a function, named template, global variable or parameter, mode, key, attribute set, accumulator, item type or character map is declared, as seen from a module - with its parameters and types, and its documentation: its documentation note, or a comment just before it. When more than one module declares it, the one used, with the highest import precedence, is first.
find_references The references to one of these, as Find All References finds them - in the modules that use it and the XSpec files that test it - with each reference's line. The XSpec uses are listed last, as the tests, each with the scenario it's in.
describe_type An XSLT 4.0 named item type: a record type's fields, with their types and @field documentation, or an enumeration type's values.
xpath_function The signature and description of a built-in XPath or XSLT function, for XPath 3.1 or 4.0 - for a function declared in a stylesheet, the assistant uses find_declaration.

The tools only read files: they don't change them, or run stylesheets or tests.

GitHub Copilot

With the server on, Copilot finds it by itself: its tools are listed with the other MCP tools in Copilot Chat's agent mode.

Claude Code

Run XSLT: Set Up MCP Server for Claude Code from the Command Palette - it offers to turn the server on, if it isn't, and asks whether to set it up for all your projects or only this one. It runs Claude Code's claude mcp add command for you. A Claude Code session started after that can use the tools, whether it runs in Visual Studio Code or in a terminal of its own; in a session already running, run /mcp to connect.

If the claude command isn't found - for example, it isn't on the path Visual Studio Code uses - the claude mcp add command is copied instead: run it in a terminal - for one project, in that project's folder.

Security

The server only accepts connections from your own computer (127.0.0.1), and each request needs a token that the extension makes once and keeps in Visual Studio Code's secret storage - it doesn't expire. Claude Code keeps the token in its own settings; a copied claude mcp add command includes it, so keep the command private. To make a new token - for example, if the old one has been shared - run XSLT: Reset MCP Server Token. Copilot uses the new token straight away, and Claude Code is set up again with it - for all projects, or for a project in the workspace - where it was set up with the old one.

The server listens at the port of XSLT.mcp.port (6745 by default). With more than one Visual Studio Code window open, the first one opened has the server. Its tools work best for the files of that window's workspace: a relative path is taken from its first folder, and a module's top-level stylesheet is found from the workspace's modules. The XSLT MCP Server output channel shows whether the server started, or why it didn't - for example, because another program uses the port.

Documentation notes

XSLT 4.0 documentation notes - xsl:note format="xdoc-md" - use Markdown with @param and @return tags, in the style of Javadoc: a format that assistants already know. An assistant can read a function's note to understand it, and can write notes too - for example, when asked to document the functions in a stylesheet. As the extension checks the @param tags against the parameters, a missing or misnamed parameter in a note is reported straight away.

Debugging output

The output of xdm:debug() in xsl:message is plain, labelled text: each variable's value in XPath syntax, with its type where it isn't obvious, and each node with its path. Copied from the terminal into a chat, it gives an assistant the actual values to reason about, rather than a description of the problem.

Running XSLT

Quick Run creates ordinary tasks in the workspace's tasks.json file, and each task shows the Saxon command line it runs in the terminal. An assistant that can run commands can run a transform in the same way.

The Agents window

Visual Studio Code's Agents window, for running agent sessions and reviewing their changes, only runs the extensions on a list chosen by Microsoft, and the XSLT/XPath extension isn't on it yet. Without the extension, XSLT files in the Agents window have plain XML highlighting, with none of the extension's features - and if Red Hat's XML extension is installed, it may report errors against its XSLT 3.0 schema. To run the extension in the Agents window, add this to your user settings - see Settings:

"extensions.supportAgentsWindow": { "deltaxml.xslt-xpath": true }

Current limitations

The MCP server's tools only read files: an assistant can't yet ask the extension to run a stylesheet, an XSpec test or an XPath expression, though it can run a Quick Run task's Saxon command itself. Tools for these may be added in a future release.

In the Problems view, problems are only shown for files open in an editor, as by most language extensions: a stylesheet an assistant changes that isn't open has none there until it's opened. With the MCP server on, an assistant can check such a file with lint_file.

On this page