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.61. 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.62. 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.63. 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.64. 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.65. 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.66. Content Completion in attribute value templates

Content Completion in attribute value templates