Creating XPath expressions

The XML Path Language (XPath) is an XSL sub-language designed to uniquely identify or address parts of a source XML document. An XPath expression can be used to search through an XML document, and extract information from the nodes (any part of the document, such as an element or attribute) in it.

You can launch the XPath Expression wizard in the following ways:

For more information about XPath, see www.w3.org/TR/xpath.

To create an XPath expression using the XPath Expression wizard, follow these steps:

  1. Launch the XPath Expression wizard using one of the methods described previously. 
  2. Select an XML file to use to build your XPath expression.
  3. In the Source Tree page, select the node you want to be your context node. The context node is the starting point for your XPath expression; it can be the document root node or any node contained in the root node.
  4. Right-click it, and click Set Context. It appears in the Evaluation Context field.
  5. The empty field below the Evaluation Context field contains your XPath expression. You can create or modify it by selecting the appropriate options from the Source Tree and Reference pages in the XPath Expression wizard.
  6. The Source Tree page tree lists all the nodes (such as attributes and elements) in your XML document. Select the node you want to search for, right-click it, and click Add to Expression. The node will appear in the expression field. You can repeat this process for all the nodes you want to add to the expression.
  7. Click the Reference tab. The Reference page lets you specify functions, operators, and a location path for your XPath expression.
  8. Expand Functions Reference. It contains the following options:
    1. Node set. Functions that apply to node sets.
    2. String. Functions used for dealing with strings.
    3. Boolean. Functions used for Boolean mathematics.
    4. Number. Functions used to manipulate numeric values.
    5. XSLT. XSLT functions used in XPath expressions.
    6. User defined. Functions that are defined by the user.
  9. Expand the Functions Reference option you want to work with, then right-click it and click Add to Expression to add it to your XPath Expression. For more information about each option, you can select it, and information about it will appear at the bottom of the Reference page in the Details pane. You can also refer to the related reference files.
  10. Expand Syntax Reference . It contains the following options:
    1. Axis specifiers. Determines the direction you move within the XML document.
    2. Node tests. Specifies what kinds of nodes to search for.
    3. Operators . Contains the following options:
      1. Node Set. Operators that combine or define paths
      2. Boolean. Operators that compare string or numeric expressions, or Boolean values.
      3. Number. Operators that can be used to manipulate numeric values.
  11. Expand the Syntax Reference option you want to work with, then right-click it and click Add to Expression to add it to your XPath Expression. For more information about each option, you can select it, and information about it will appear at the bottom of the Reference page in the Details pane. You can also refer to the related reference files.
  12. You can also edit your expression manually in the expression field. Content assist is available and can be invoked by clicking Ctrl + Space. Double-click the option you want to add to your XPath expression
  13. Your XPath expression is automatically evaluated as you create it. The results of it appear in node format in the Results Tree page. Click the Result Source tab if you want to see your results in source code format. If you do not want your XPath expression automatically evaluated as you type it, you can change this option in the XPath expression builder preference page. Click the XPath builder preference page button This graphic is the XPath builder preference page button to access it.
  14. Click OK when you have finished your XPath expression.

If you launched the XPath Expression wizard using the XSL editor, your XPath expression appears in your XSL file after you click OK. If you launched it from an XSL editor wizard, it will appear in the field you created it for.

Related concepts
XPath expressions
Related tasks
Specifying XPath Expression builder preferences
Related reference
XPath expression wizard - Syntax Reference options
XPath expression wizard - Functions Reference options

Feedback