Source XPath
The Source XPath is specified in the Select Columns dialog. It determines what nodes in the document are available for selection as X-Axis and Y-Axis data. The Column Search Depth combo box determines how many descendant levels will be searched to return nodes that may be used for the X-Axis and Y-Axis data.
After a new Source XPath has been selected, clicking Update Columns refreshes the available selections (in the dialog) for the X-Axis and Y-Axis. If predicates are included in the XPath expression (for example, /Data/Region[1] uses the [1] predicate to select the first Region element), then the Include Indices check box must be checked. If you modify the Source XPath expression be sure to click Update Columns.
Source XPath from cursor location
To explain what Source XPath is selected when the Select Columns dialog is opened, we'll use the XML document shown below. It is named YearlySales.xml and is available in the folder C:\Documents and Settings\<username>\My Documents\Altova\XMLSpy2025\Examples\Tutorial.
<?xml version="1.0" encoding="UTF-8"?>
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="YearlySales.xsd">
<Region id="Americas">
<Year id="2005">30000</Year>
<Year id="2006">90000</Year>
<Year id="2007">120000</Year>
<Year id="2008">180000</Year>
<Year id="2009">140000</Year>
<Year id="2010">100000</Year>
</Region>
<Region id="Europe">
<Year id="2005">50000</Year>
<Year id="2006">60000</Year>
<Year id="2007">80000</Year>
<Year id="2008">100000</Year>
<Year id="2009">95000</Year>
<Year id="2010">80000</Year>
</Region>
<Region id="Asia">
<Year id="2005">10000</Year>
<Year id="2006">25000</Year>
<Year id="2007">70000</Year>
<Year id="2008">110000</Year>
<Year id="2009">125000</Year>
<Year id="2010">150000</Year>
</Region>
</Data>
The following cases are possible:
•If the cursor is placed anywhere inside the start tag (including in an attribute-value) or end tag of the Data element, or anywhere inside the Data element but not within a descendant node, the Source XPath will be: /Data
•If the cursor is placed anywhere inside the start tag (including in an attribute-value) or end tag of any Region element, or anywhere inside a Region element but not within a descendant node, the Source XPath will be: /Data/Region
•If the cursor is placed anywhere inside the start tag (including in an attribute-value) or end tag of a Year element, or anywhere inside a Year element, the Source XPath will be: /Data/Region[N]/Year. The predicate filter [N] selects the particular Region element inside which the selected Year element is. So the X-Axis and Y-Axis data selections will be restricted to Year elements of this particular Region element.
•If you wish to select just one Region element, say: /Data/Region[1], then highlight this element, that is, the first Region element as shown in the screenshot below.
• Similarly, highlighting two Region elements will generate an XPath expression that selects these two Region elements only.
The Source XPath expression can be edited subsequently in the Select Columns dialog.
In Grid View, selection is done by clicking a node or marking a range. The Source XPath that is generated from the Grid View selection is as described above for Text View.
Include indices in XPath
The Include Indices check box determines whether predicate filters in the XPath expression are used, whether these predicate filters are entered automatically at the time the Select Columns dialog is called or whether they are entered manually. For example, if the cursor is placed inside a descendant element of the first Region element of the document and the Include Indices check box is checked, then the automatically entered XPath expression will be, for example: /Data/Region[1]/Year. If the Include Indices check box were not checked, then the expression would be: /Data/Region/Year.
The Include Indices check box also determines whether any predicate entered manually is retained. Therefore, if you wish to use predicates in the Source XPath expression, you must check the Include Indices check box.
Implications of Source XPath selections
Note the following implications of the Source XPath selection.
•The number of items in the sequence returned by the Source XPath determines the number of ticks on the X-Axis. The number of ticks on the X-Axis can be changed in only one other way besides by modifying the Source XPath: by selecting a number of labels for any series, which number is more than the number of ticks. See X-Axis Selection for more information about this scenario.
•The Source XPath node is the ancestor node for all nodes available for X-Axis and Y-Axis data selection and for all XPath expressions you may enter.
•As a result of the above two points, note that any change to the Source XPath expression affects not only the number of ticks on the X-Axis but also the context for any XPath expression related to the chart.
For example, here are the implications of some XPath expressions with respect to the XML document shown above.
•/Data/Region: Returns the three Region elements, so three ticks on the X-Axis. Each Region element will in turn be the context node for XPath expressions.
•/Data/Region/Year: Returns 18 Year elements, so 18 ticks on the X-Axis. Each Year element will in turn be the context node for XPath expressions.
•/Data/Region[1]/Year: Returns the six Year element children of the first Region element, so six ticks on the X-Axis. Each Year element of the first Region element will in turn be the context node for XPath expressions.
•distinct-values(//Year/@id): Returns six items (the distinct values of the Year/@id attribute: 2005, 2006, 2007, 2008, 2009, 2010). However, since this XPath expression returns no node item, it cannot be a context node for any XPath expression. If the items in this sequence are to be used to target nodes in the XML document (using, say, the current() function (shorthand: .)), then the XPath expression using the current item must start from the document root in order for the context to be established. For example: /Data/Region[1]/Year[@id eq .].