Overview
DeltaXignia's XSLT/XPath extension for Visual Studio Code supports XSLT 3.0 and XPath 3.1, and the XSLT 4.0 and XPath 4.0 features implemented in Saxon 13.
The aim is to make writing, reviewing, testing and debugging XSLT and XPath easier.
The extension understands XPath expressions within the XSLT semantically, so it can detect problems immediately, whether code is written manually or generated by an AI assistant, navigate directly to declarations across imported modules, safely rename variables, functions and templates, and step through XPath expressions in the debugger. It distinguishes variables, functions and node tests, tracks where each is declared, and uses this information throughout editing, navigation, refactoring and debugging.
Getting started
- Install the extension and open an XSLT file - editing, highlighting and checking need no setup.
- To run or debug stylesheets, set
XSLT.tasks.saxonJarto the path of your Saxon jar (Saxon-HE is fine), with a Java runtime on the PATH - see The Saxon jar. - Press ⌘⌥R (Ctrl+Alt+R on Windows/Linux) to Quick Run the stylesheet with the XML file you last had open - shown in the status bar, where you can pick another.
Writing XSLT
Problems are reported as you type - in XPath syntax, XSLT instructions, types and function calls, and references to declarations in other modules - many with a quick fix. Auto-completion offers the variables, functions, templates and modes in scope, and node names from the XML file you're working with. See Editing XSLT/XPath.
xsl:switch that doesn't cover an enumeration's values, with quick fixes
to add the missing casesReviewing XSLT
Hovering over a name shows its declaration - its type, and its documentation from an
xsl:note - wherever it's declared. Go to Definition, Find References, the Outline and the
XSLT Imports view help you find your way around a large stylesheet and its modules. See
Code Navigation and Code
Documentation.
Running XSLT
Quick Run runs the stylesheet in the active editor with SaxonJ, SaxonJS or SaxonC. The first run
creates a task in tasks.json, which you can edit - and you're asked for the values of
any required stylesheet parameters. Saxon's errors are listed in the Problems view, linked to the
code. See Quick Run.
Debugging XSLT
The debugger sets breakpoints and steps through templates, functions and multi-line XPath expressions, showing variables, the context item and the output written so far. Where Saxon's standard tracing stops at XSLT instructions, this debugger uses Saxon's own APIs to inject extra trace points and re-parse XPath to locate sub-expressions, so it can stop deep inside multi-line expressions and inline functions. See Debugger.
Scope
The extension supports the XSLT 4.0 and XPath 4.0 features that Saxon 13 implements. Its checks are made as you type, without compiling the stylesheet - Saxon reports anything else when the stylesheet runs. Schema-aware features aren't supported. The debugger needs SaxonJ 12 or later (any edition); SaxonJS and SaxonC stylesheets can be run, but not debugged.
Edit XML, XSLT or XPath
If you're new to VS Code, see Using VS Code for a brief introduction. For a comprehensive guide to Visual Studio Code's editor features, see the Microsoft Visual Studio Code User Guide.
Language Specific Features
XSLT and XPath specific editing features are described in the Editing XSLT/XPath page of the documentation that you are reading now. More general XML editing features are described in the Editing XML section.
The features described at Editing XSLT/XPath include:
- IntelliSense (Auto Complete)
- Syntax Highlighting
- Code Formatting
- Code Refactoring
- Symbol Renaming
- Hover Help and Signature Help
- XSLT/XPath Linter
Run XSLT - Quick Start
The quickest way to run the stylesheet in the active editor is Quick Run: press ⌘⌥R (Ctrl+Alt+R on Windows/Linux) or click the play button in the editor title bar. The first run creates an XSLT task for you, which later runs reuse.
To step through the stylesheet instead, set a breakpoint and click the debug button in the editor title
bar, or press F5 when there's no launch.json - see the Debugger.
XSLT transforms are run using Visual Studio Code Tasks.
Before configuring an XSLT task you should ensure that you open a
Workspace folder (⌘O) from Visual Studio Code.
The configuration is saved in a tasks.json file in this workspace folder.
To create your first task, use the Run Build Task command (⇧⌘B).
As there is no currently configured task, you should be prompted to configure one
(if another extension inhibits this, run Configure Task instead). You
can then select the Saxon Transform (New) (SaxonJ), Saxon-JS Transform (New)
(SaxonJS) or SaxonC Transform (New) (SaxonC) task.
A task will be added to the tasks.json task with default properties. To further
configure the
task, these properties can be changed or other properties added. Auto-completion and hints are
provided to
assist in the task configuration. Next time you press ⇧⌘B your task
will be run
in a Task tab in the Terminal window (toggled with ⌘J).
More on running XSLT
XSLT tasks are explained in full on the Tasks page. More general information can be found in the Visual Studio Code Tasks documentation.