-
Notifications
You must be signed in to change notification settings - Fork 4
XSLT 3.0 in Visual Studio Code
Visual Studio Code with DeltaXML’s XSLT extension provides a comprehensive set of language features for XSLT 3.0. This page outlines how these language features can be used to help you work with XSLT more effectively.
Screenshot of XSLT/XPath extension with auto-formatted XSLT with syntax-highlighting, problem reporting on 'report' mode-name and symbol-outline (default dark+ theme):
Accurate and responsive syntax highlighting for XSLT and XPath expressions is provided by a hand-crafted semantic token provider. Code is processed character by character, avoiding the unpredictable behaviour of line by line regex based tokenisers on the most complex expressions.
Syntax highlighting is currently only enabled by default in VSCode's built-in themes. This is because some extension themes may not yet have specific language support for VSCode's 'Semantic Highlighting' as used by this extension.
To enable syntax highighting for a custom theme you need to change User Settings. For example, to enable syntax highlighting for XSLT in the City Lights theme use:
{
"editor.semanticTokenColorCustomizations":{
"[City +Lights]": {"enabled": true}
},
}
Or, to enable syntax highlighting for all themes:
{
"editor.semanticTokenColorCustomizations":{
"enabled": true
},
}
Auto-complete combines built in XSLT symbols (depending on context) along with symbols from the current XSLT and included/imported XSLT.
In an empty file, typing the '<' character and selecting the xsl:stylesheet auto-complete option results in a boilerplate XSLT stylesheet being inserted. This includes the required namespace declarations and a basic xsl:template and can be used as a starting point for a new XSLT stylesheet.
Symbols include names for:
- accumulators
- attribute name tests
- attribute sets
- anonymous function parameters
- element name tests
- functions
- function parameters
- xsl:iterate parameters
- xsl:key names
- XSLT instructions
- template modes
- template names
- XSLT variables
- xmlns declarations - for supported namespaces
- XPATH range variables for 'let', 'every','for' and 'some'
For XSLT/XPATH functions, help text is also shown.
XSLT instructions are auto completed with suitable attributes where relevant. Use the tab key to jump between pre-filled values.
Note that to filter auto-complete suggestions you don't need to always type the start of the name like in some other editors. For example, don't type 'xsl:' for an XSLT 'for-each' instruction
XML and XSLT/XPATH Problems are highlighted in the source code and listed in the Visual Studio Code problems tab.
The extension itself checks all symbol names are valid and in-scope for the context, it also performs basic XPATH expression checking. The checker allows more granular reporting than most XSLT editors report using just an XSLT compiler or processor.
More subtle static or runtime problems reported by the Saxon processor are shown in the terminal when the XSLT is run. In most cases problems reported by Saxon should also result in the problem source code being highlighted. There are known exceptions however where the Saxon error message is not properly parsed by the extension.
This extension shows all problems not just the first one (which may not be the most significant).
Declarations for variables that are not referenced will be shown greyed out, highlighting that either the code is incomplete or that there is a coding error.
Indentation for XML and for multi line nested XPATH expressions is provided by the extension.
To work most effectively, as-you-type and format-on-save formatting should be enabled in the VSCode settings.
The symbol outline view shows a tree view of the XSLT structure with symbol names added. The order of items in the tree view can be set to show document order. The tree view can also be set to be synchronized with the currently selected item.
Shown at the top of the editor, the Breadcrumbs control shows the nesting information of the currently selected element. This control can also be clicked on to navigate up the document tree.
Navigate to any symbol within a file using the ⇧⌘O
(Windows, Linux Ctrl+Shift+O) shortcut. Typing in the input box will show a matching symbols list, using the up/down arrow keys to select the symbol you need and then press Enter
or Ctrl-Enter
to scroll to the symbol position.
To navigate to the location where a symbol is defined, hold down the CMD button and click on the symbol name. This feature is also available from the right-click context menu.
To navigate to a specific XPath location, use the ⇧⌘P
shortcut and then select the XML: Goto XPath
command. Enter or paste-in the XPath location (full XPath expressions are not supported here) and press Enter
. Note that the input box is initially filled with the currently selected XPath location.
This extension supports start-tag renaming and auto tag-close. Snippets for literal result elements are included in auto complete options.