-
Notifications
You must be signed in to change notification settings - Fork 4
XSLT Tasks
The XSLT/XPATH extension allows XSLT files located within a VSCode Workspace Folder to be compiled and run using the Saxon XSLT processor for Java from Saxonica.
A custom VSCode XSLT Task Provider allows for the management of a set of tasks used to define XSLT transform configurations. Each configuration is used to control the environment is which an XSLT transform runs.
When a task is run from VSCode, the Saxon XSLT processor is invoked via its command line interface. The VSCode Terminal View will show the stdout fro Saxon. The stdout is also processed by the extension to check for compile time or run time errors. Most errors (the generic error parser is not faultless) will also be highlighted in the VSCode Problem View and highlighted in the code editor. The extension also includes its own code diagnostics to provide as-you-type error reporting.
-
Ensure you have a Folder or Workspace Folder open in VSCode
-
In VScode, press
Shift-CMD-P
then enter 'tasks:' to see Task Commands:
Select the 'tasks: Configure Task' command, a list of tasks will be shown:
The existing tasks, plus a 'xslt: Saxon Transform (New) entry are listed, as shown above, select this last entry to create a new task.
If a new task is created the 'label' property should be edited to describe the specific task.
To run a task, press Shift-CMD-B
. If there's no default task, select the required task from the list that is shown.
Any compile-time or run-time errors/warnings are shown in the VSCode Problems panel. Select an item in the Problems panel, to see the problem highlighted in the XSLT.
Each task can be configured to set options and XSLT parameters for an XSLT Transform. VSCode Variables like ${workspaceFolder} can be used within properties in a task configuration.
Sample tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "xslt",
"label": "Basic Transform",
"saxonJar": "${config:XSLT.tasks.saxonJar}",
"xsltFile": "${workspaceFolder}/basic.xsl",
"xmlSource": "${workspaceFolder}/basic.xsl",
"resultPath": "${workspaceFolder}/xslt-out/result1.xml",
"parameters": [
{"name": "p1", "value": "p1value"},
{"name": "p2", "value": "p2value"}
],
"initialMode": "main",
"classPathEntries": ["/xrc/utilitiy.class1", "/xrc/utility.class2"],
"group": {
"kind": "build"
},
"problemMatcher": [
"$saxon-xslt"
]
},
{
"type": "xslt",
"label": "Compile Active XSLT File",
"saxonJar": "${config:XSLT.tasks.saxonJar}",
"xsltFile": "${file}",
"xmlSource": "${file}",
"resultPath": "${workspaceFolder}/xslt-out/result1.xml",
"group": {
"kind": "build"
},
"problemMatcher": [
"$saxon-xslt"
]
}
]
}
Saxon 9.9 or later must be installed on the local machine. By default, the location of the Saxon Jar should be set in User Settings for the XPath Embedded extension.
Alternatively, the saxonJar property in tasks.json can be modified to use a value other than that set in User Settings.
Setting the Saxon Jar location in VSCode User Settings: