Editing XSLT stylesheets

<oXygen/> provides special support for developing XSLT 1.0 / 2.0 stylesheets.

Validating XSLT stylesheets

Validation of XSLT stylesheets documents is performed with the help of an XSLT processor configurable from user preferences according to the XSLT version: 1.0 or 2.0. For XSLT 1.0 the options are: Xalan, Saxon 6.5.5, Saxon 8B, Saxon 8SA (if the user installs it as additional package), MSXML 4.0, MSXML.NET, a JAXP transformer specified by the main Java class. For XSLT 2.0 the options are: Saxon 8B, Saxon 8SA (if the user installs it as additional package), a JAXP transformer specified by the main Java class.

Custom validation of XSLT stylesheets

If you need to validate an XSLT stylesheet with other validation engine than the built-in ones you have the possibility to configure external engines as custom XSLT validation engines in <oXygen/>. After such a custom validator is properly configured in Preferences it can be applied on the current document with just one click on the External Validation toolbar. The document is validated against the schema declared in the document.

Figure 4.46. External validation toolbar

External validation toolbar

There are two validators configured by default:

MSXML 4.0

included in <oXygen/> (Windows edition). It is associated to the XSL Editor type in Preferences.

MSXML.NET

included in <oXygen/> (Windows edition). It is associated to the XSL Editor type in Preferences.

Content Completion in XSLT stylesheets

The content completion assistant adds special features for editing XSLT stylesheets.

Inside XSLT templates of an XSLT stylesheet the content completion presents also all the elements allowed in any context by the schema associated to the result of applying the edited stylesheet. That schema is defined by the user in the Content Completion / XSL preferences. There are presented all the elements because in a template there is no context defined for the result document so the user is allowed to insert any element defined by the schema of the result document.

Namespace prefixes in scope for the current context are presented at the top of the content completion window to speed the insertion of prefixed elements into the document.

Figure 4.47. Namespace prefixes in the content completion window

Namespace prefixes in the content completion window

Content Completion in XPath expressions

In XSLT stylesheets the content completion assistant provides all the features available in the editor for XML documents and also adds some enhancements. In XPath expressions used in attributes of XSLT stylesheets elements like match, select and test it offers XPath functions, XSLT functions, XSLT axes and user defined functions. If a transformation scenario was defined and associated to the edited stylesheet the content completion assistant computes and presents elements and attributes based on the input XML document selected in the scenario and on the current context in the stylesheet. The associated document is displayed in the XSLT input view.

Content Completion for XPath expressions is started:

  • on XPath operators detected in one of the match, select and test attributes of XSLT elements: ", ', /, //, (, [, |, :, ::, $

  • for attribute value templates of non XSLT elements, that is the '{' character is detected as the first character of the attribute value

  • on request if the combination CTRL + Space is pressed inside an edited XPath expression

The items presented in the content completion window are dependent on the context of the current XSLT element, the XML document associated with the edited stylesheet in the transformation scenario of the stylesheet and the XSLT version of the stylesheet (1.0 or 2.0). For example if the document associated with the edited stylesheet is:

<personnel>
    <person id="Big.Boss">
        <name>
            <family>Boss</family>
            <given>Big</given>
        </name>
        <email>chief@oxygenxml.com</email>
        <link subordinates="one.worker"/>
    </person>
    <person id="one.worker">
        <name>
            <family>Worker</family>
            <given>One</given>
        </name>
        <email>one@oxygenxml.com</email>
        <link manager="Big.Boss"/>
    </person>
</personnel>
                    

and you enter an element xsl:template using the content completion assistant the match attribute is inserted automatically, the cursor is placed between the quotes and the XPath content completion assistant automatically displays a popup window with all the XSLT axes, XPath functions and elements and attributes from the XML input document that can be inserted in the current context. The set of XPath functions depends on the XSLT version declared in the root element - xsl:stylesheet (1.0 or 2.0).

Figure 4.48. Content Completion in the match attribute

Content Completion in the match attribute

If the cursor is inside the select attribute of an xsl:for-each, xsl:apply-templates, xsl:value-of or xsl:copy-of element the content completion proposals are dependent of the path obtained by concatenating the XPath expressions of the parent XSLT elements xsl:template and xsl:for-each like the following figure shows:

Figure 4.49. Content Completion in the select attribute

Content Completion in the select attribute

Also XPath expressions typed in the test attribute of an xsl:if or xsl:choose / xsl:when element benefit of the assistance of the content completion.

Figure 4.50. Content Completion in the test attribute

Content Completion in the test attribute

XSLT variable references are easier to insert in XPath expressions with the help of the content completion popup triggered by the $ character which signals the start of such a reference in an XPath expression.

Figure 4.51. Content Completion in the test attribute

Content Completion in the test attribute

The same content completion assistant is available also in attribute value templates of non XSLT elements if the '{' character is the first one in the value of the attribute.

Figure 4.52. Content Completion in attribute value templates

Content Completion in attribute value templates

Code templates

When the content completion is invoked by pressing CTRL+Space it also presents a list of code templates specific to the type of the active editor. Such a code template provides a shortcut for inserting a small document fragment at the current caret position. <oXygen/> comes with a large set of ready-to use templates for XSL and XML Schema documents.

Example 4.3. The XSL code template called Template-Match-Mode

Typing t in an XSL document and selecting tmm in the content assistant pop-up window will insert the following template at the caret position in the document:

<xsl:template match="" mode="">

</xsl:template>
                            

Other templates can be easily defined by the user. Also the code templates can be shared with other users.

The XSLT Input View

The structure of the XML document associated to the edited XSLT stylesheet is displayed in a tree form in a view called XSLT Input. The tree nodes represent the elements of the document.

If you click on a node, the corresponding template from the stylesheet will be highlighted. A node can be dragged and dropped in the editor area for quickly inserting xsl:template, xsl:for-each or other XSLT elements with the match / select / test attribute already filled with the correct XPath expression referring to the dragged tree node and based on the current editing context of the drop spot.

Figure 4.53. XSLT input view

XSLT input view

For example for the following XML document

<personnel>
    <person id="Big.Boss">
        <name>
            <family>Boss</family>
            <given>Big</given>
        </name>
        <email>chief@oxygenxml.com</email>
        <link subordinates="one.worker"/>
    </person>
    <person id="one.worker">
        <name>
            <family>Worker</family>
            <given>One</given>
        </name>
        <email>one@oxygenxml.com</email>
        <link manager="Big.Boss"/>
    </person>
</personnel>
                

and the following XSLT stylesheet

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        version="2.0">
    <xsl:template match="personnel">
        <xsl:for-each select="*">
            
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
                

if you drag the given element and drop it inside the xsl:for-each element a popup menu will be displayed.

Figure 4.54. XSLT Input drag and drop popup menu

XSLT Input drag and drop popup menu

Select for example Insert xsl:value-of and the result document will be:

Figure 4.55. XSLT Input drag and drop result

XSLT Input drag and drop result

The Stylesheet Templates view

The list of all templates of the edited stylesheet is presented in the view called Stylesheet Templates.

Figure 4.56. The Stylesheet Templates view

The Stylesheet Templates view

It has two operation modes: the name and match attributes of templates presented in separate columns of the table, and the name and match attributes presented in the same column. In the second case the entry in the Name + Match column is composed of the value of the name attribute followed by a space character and the value of the match attribute. The operation mode is switched from the action Join/Split name and match columns available on the toolbar of the view.

The view provides three levels of syncronization with the editor panel:

No selection update
The templates list selection is not synchronized with the caret position in the editor panel.
Selection update on document change
The templates list selection is synchronized with the caret position in the editor panel when the document is modified by an editing action.
Selection update on caret move
The templates list selection is synchronized with the caret position in the editor panel in real time, that is the list selection is updated for every move of the caret in the editor panel.

All the columns of the table with the templates are sortable in ascending and descending order. The first click on the column name sorts the rows of the table in ascending order after the clicked column, the second click sorts the table in descending order and the third click returns to the unsorted state, that is the order of the templates in the stylesheet.

A template can be located easily in the list using only the keyboard. If the focus is in the Name column, type the first characters of the template name and the selection moves to that template in the list. In a similar way if the focus is in the Match or Mode column, typing the first characters of the value of the match attribute or the mode attribute moves the selection to that template in the list.

Finding XSLT references and declarations

Note

All the following actions can be applied on named templates, attribute sets, functions, decimal formats, keys, variables or parameters only. In case they are applied on other items, a warning message will pop-up.

  • XSL+ ->References in project (Ctrl+Shift+R): Searches in the project all references of the item found at current cursor position.

    Note

    For faster access, a shortcut to this action is also added in the XSL References toolbar.

  • contextual menu of current editor+Search->References in file: Searches in the current file all references of the item at the current cursor position.

  • contextual menu of the current editor+Search->References starting from file: Searches all references of the item at the cursor position in the current edited file and all its included and imported files.

  • contextual menu of the current editor+Search->References starting from...: Opens a dialog that allows the user to specify the list of files used to start searching from. Pressing OK begins searching all references of the item at the cursor position in the selected files and their included and imported files.

  • XSL+ ->Declarations in project (Ctrl+Shift+D): Searches in the project all declarations of the item found at current cursor position.

    Note

    For faster access, a shortcut to this action is also added in the XSL References toolbar.

  • contextual menu of current editor+Search->Declarations in file: Searches in the current file all declarations of the item at the current cursor position.

  • contextual menu of the current editor+Search->Declarations starting from file: Searches all declarations of the item at the cursor position in the current edited file and all its included and imported files.

  • contextual menu of the current editor+Search->Declarations starting from...: Opens the Start locations dialog that allows the user to specify the list of files used to start searching from. Pressing OK begins searching all declarations of the item at the cursor position in the selected files and all their included and imported files.

  • XSL->Occurrences in file (Ctrl+Shift+U): Searches all occurrences of the item at the caret position in the currently edited file.

XSLT refactoring actions

  • XSL+ ->Create template from selection...: Opens a dialog that allows the user to specify the name of the new template to be created. After pressing OK, the template is created and the selection is replaced by a

    xsl:call-template

    instruction referring the just created template.

    Note

    The selection must contain wellformed elements only.

  • XSL+ ->Create stylesheet from selection...: Creates a separate stylesheet and replaces the selection with a

    xsl:include

    instruction referring the just created stylesheet.

    Note

    The selection must contain a well formed top level element.

  • XSL->Extract attributes as xsl:attributes...: Extracts the attributes from the selected element and represents each of them with a

    xsl:attribute

    instruction.

    For example from the following element

    <person id="Big{test}Boss"/>
                            

    you would obtain

    <person>
        <xsl:attribute name="id">
            <xsl:text>Big</xsl:text>
            <xsl:value-of select="test"/>
            <xsl:text>Boss</xsl:text>
        </xsl:attribute>
    </person>
                            
  • XSL+ ->Rename occurrences in project...: Renames all occurrences of the item at current cursor position in the entire project. The possible changes to be performed on the documents can be previewed prior to documents altering.

    In the upper part of the Rename template dialog there are displayed all the project files in which the item was found, while in the central part of the dialog it can be seen where the replacements will be performed. The user has the possibility to allow or deny the altering of a file.

  • XSL->Rename occurrences in file...: Renames all occurrences of the item at current cursor position in the entire file. The possible changes to be performed on the current file can be previewed prior to document altering.

  • XSL->Rename occurrences starting from file...: Renames all occurrences of the item at current cursor position in the currently edited file and all its included and imported files. The possible changes to be performed can be previewed prior to document(s) altering.

  • XSL->Rename occurrences starting from ...: Opens a dialog that allows the user to select the files to begin searching from, then renames all occurrences of the item at current cursor position in the selected files and all their included and imported files. The possible changes to be performed can be previewed prior to document(s) altering.