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:
- From the pop-up menu of any select or match attributes
in an XSL file. Select the attribute, right-click it, and click XPath
Expression.
- From any of the XSL editor wizards in which you can specify an XPath expression
for a field value. In the appropriate wizard, click the XPath button.
For more information about XPath, see www.w3.org/TR/xpath.
To create an XPath expression using the XPath
Expression wizard, follow these steps:
- Launch the XPath Expression wizard using one of the methods described
previously.
- Select an XML file to use to build your XPath expression.
- 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.
- Right-click it, and click Set Context. It appears in the Evaluation Context field.
- 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.
- 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.
- Click the Reference tab. The
Reference page lets you specify functions, operators, and a location path
for your XPath expression.
- Expand Functions Reference. It
contains the following options:
- Node set. Functions that apply to node
sets.
- String. Functions used for dealing with
strings.
- Boolean. Functions used for Boolean
mathematics.
- Number. Functions used to manipulate
numeric values.
- XSLT. XSLT functions used in XPath expressions.
- User defined. Functions that are defined
by the user.
- 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.
- Expand Syntax Reference . It
contains the following options:
- Axis specifiers. Determines the
direction you move within the XML document.
- Node tests. Specifies what kinds of nodes
to search for.
- Operators . Contains the following options:
- Node Set. Operators that combine or define
paths
- Boolean. Operators that compare string or
numeric expressions, or Boolean values.
- Number. Operators that can be used to manipulate
numeric values.
- 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.
- 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
- 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
to
access it.
- 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.