Using XPath Expressions

SharePoint Designer provides an XPath Express Builder for creating XPath expression. XPath is a language that can locate and process XML information. It can be used in the data view to create expressions to provide advanced sorts and calculated fields for data sources, whether they are XML sources or other sources like SQL databases or SharePoint lists. If you use XPath expressions on non-XML sources, the data is rendered first as XML and then the XPath expression is applied, so you may see a performance impact.

Working with the XPath Expression Builder is similar to working with functions in Excel. You can create formulas of the following types:

  • Math/Number: These functions perform mathematical operations such as returning the average, finding the minimum or maximum value, rounding a value up or down to the next integer, or formatting the number.

  • Text/String: These functions perform operations such as concatenating two values, calculating the length of a string, normalizing the spaces in a string of text, evaluating whether a string starts with or contains the value provided, or translating characters if present in a string with a new character.

  • Field/Node: These functions return values particular to the structure of the XML such as the namespace URI or all the comments or processing instructions present in the document.

  • Date/Time: These functions allow you to format the date or the date and time, return today’s date, and evaluate whether items have been created in the last two days.

  • Boolean: The Boolean operations evaluate whether conditions are met or not. You can provide a condition, determine whether the current user has rights, evaluate whether a value is null, or set automatically to true or false.

  • Parameters: The parameters function returns the values of the selected parameter such as firstrow or nextpagedata.

  • XPath Axes: These functions return related nodes to the context node such as child, descendant, parent, and ancestor.

  • Operators: The operator category allows you to select operators commonly used in equations such as not equal to, minus, plus, greater than, and less than.

  • XSLT: The XSLT functions allow you to determine whether elements or functions are available for the string provided, generate unique IDs for the context node, or return nodes that match a key name and value.

You can use XPath expressions to define additional columns of your data, create advanced sort or filter arguments, or calculate conditional formatting rules. Your XPath expressions are performed on the rows of your data, not the aggregation of the rows. For example, if you have data that contains orders and values for each order, sales tax, and shipping, XPath can be used to calculate the total cost (order + sales tax + shipping) but it cannot be used to add the sales tax value for all rows.

Tip

Because XPath is a language, users that are familiar with it can edit the XPath expressions themselves instead of using the XPath Expression Builder in SharePoint. For others, the Expression Builder makes creating functions for rows of your data straightforward.


To insert a column based on an XPath expression in your data view using the SharePoint Designer XPath Expression Builder, follow these steps:

1.
Open the page with the Data View Web Part using SharePoint Designer.

2.
To open the data view common tasks menu, right-click the Data View Web Part and choose Show Common Control Tasks. Click the Edit Columns link.

Or:

To open the data view common tasks menu, left-click the > next to the top right corner of your Data View Web Part. Click the Edit Columns link.

Or:

To edit using the top navigation data view menu in SharePoint designer, make sure the Data View Web Part that you want to modify is active/selected. Choose Edit Columns from the Data View Web Part menu in SharePoint designer.

3.
Select the Add Formula Column option from the bottom of the Available fields list and click Add.

4.
Enter your XPath expression in the Edit the XPath expression field as shown in Figure 20.25. You can double-click fields or functions you want to insert into the expressions. The preview field allows you to preview the results.

Figure 20.25. Entering an XPath expression


5.
Click OK to save the expression.

6.
Click OK to exit the Edit Columns dialog box.

7.
Choose Save from File menu to save your Web Part page.

You can customize the table heading for your XPath formula column by editing the XSL for the Data View Web Part within the Web Part page. To edit the formula table heading, follow these steps:

1.
Open the page with the Data View Web Part using Internet Explorer.

2.
Left-click the down arrow for the Web Part and choose Modify Shared Web Part.

3.
Click XSL Editor.

4.
Select the text that is currently being used in the table header row (HTML value of <th>) and replace with your new text.

5.
Click Save to exit XSL Editor.

6.
Click OK to save the Web Part changes.

You can also use XPath expressions to do advanced sorting, provide advanced filtering, or to provide conditional format expressions. To do any of these, follow these steps:

1.
Open the page with the Data View Web Part using SharePoint Designer.

2.
To open the data view common tasks menu, right-click the Data View Web Part and select Show Common Control Tasks. Click the Sort and Group link, Filter link, or Conditional Formatting link as appropriate for your XPath expression.

Or:

To open the data view common tasks menu, left-click the > next to the top right corner of your Data View Web Part. Click the Sort and Group link, Filter link, or Conditional Formatting link as appropriate for your XPath expression.

Or:

To edit using the top navigation data view menu in SharePoint designer, make sure the Data View Web Part that you want to modify is active/selected. Click the Sort and Group link, Filter link, or Conditional Formatting link from the Data View Web Part menu in SharePoint designer as appropriate for your XPath expression.

3.
If you want to use XPath to calculate the sort order, select the Edit Sort Expression button.

Or:

If you want to use XPath to calculate the filter criteria, click the Advanced button on the Filter Criteria dialog.

Or:

If you want to use XPath to calculate the conditional formatting criteria, click the Advanced button on the Condition Criteria dialog.

4.
Enter your XPath expression in the Edit the XPath Expression field. You can double-click fields and functions you want to insert into the expression. The preview field allows you to preview the results.

5.
Click OK to save the expression.

6.
Click OK to exit the Edit Columns dialog box.

7.
Choose Save from the File menu to save your Web Part page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.137.108