Edit online

Content Completion in XPath Expressions

In XSLT stylesheets, the Content Completion Assistant provides all the features available in the XML editor and also adds some enhancements. In XPath expressions used in attributes of XSLT stylesheets (such as @match, @select, and @test), the Content Completion Assistant offers the names of XPath and XSLT functions, XSLT axes, and user-defined functions (the name of the function and its parameters). 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.
  • The current context in the stylesheet.

The associated document is displayed in the XSLT/XQuery 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 when detected as the first character of the attribute value.
  • On request, if the combination Ctrl + Space is pressed inside an edited XPath expression.

The proposals presented in the Content Completion Assistant are dependent on:

  • The context of the current XSLT element.
  • The XML document associated with the edited stylesheet in the stylesheet transformation scenario.
  • The XSLT version of the stylesheet (1.0, 2.0, or 3.0).
    Note: The XSLT 3.0 content completion list of proposals includes specific elements and attributes for the 3.0 version.

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>

If you enter an <xsl:template> element using the Content Completion Assistant, the following actions are triggered:

  • The @match attribute is inserted automatically.
  • The cursor is placed between the quotes.
  • The XPath Content Completion Assistant automatically displays a pop-up 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, 2.0, or 3.0. Functions from other namespaces, such as maps, arrays, and math, are presented only if the namespaces are declared.

Figure 1. 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 depend on the path obtained by concatenating the XPath expressions of the parent XSLT elements <xsl:template> and <xsl:for-each> as shown in the following figure:

Figure 2. Content Completion in the @select Attribute

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

Figure 3. Content Completion in the @test Attribute

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

Figure 4. Content Completion in the @test Attribute

If the { character is the first one in the value of the attribute, the same Content Completion Assistant is available also in attribute value templates of non-XSLT elements.

Figure 5. Content Completion in Attribute Value Templates

The time delay (configured in the Content Completion preferences page) is also applied for the content completion in XPath expressions.