08.08.2017 Views

designer

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

166 Chapter 5 Working with Data Views<br />

example of a situation in which you need to edit the XSLT in Code view is to work with<br />

calculated columns.<br />

By default, SharePoint provides two columns for each numeric column. One column<br />

provides the numeric values for a list item, and the second column provides the presentation<br />

format of that numeric value. When the numeric column represents a currency,<br />

for example, the values in the presentation column contain commas, dots, and currency<br />

symbols. To calculate the sum of those currency values, you use the numeric column. If<br />

you use the presentation column to complete mathematical computations, the XPath<br />

expression results in an error, and the acronym NaN is displayed. The numeric column<br />

has the same name as the related presentation column but with a dot appended to the<br />

name.<br />

Calculated columns do not have a related numeric column. Therefore, choosing the correct<br />

column to use in your XPath expressions is not a simple task. The solution that you<br />

use in the following exercise computes the function of the nodes first, capturing the<br />

results in an XSL variable as a result-tree fragment, which is subsequently transformed<br />

using the msxsl:node-set function that can then be used as input to the sum function. If<br />

you do not want to create your own XLST code, when you configure the calculated column<br />

do not select the data type returned for the formula as Currency. Instead, create an<br />

additional column to store the currency symbol, such as $, EUR, and £.<br />

See Also Other XSLT sum solutions can be found in “Recipe 3.6. Computing Sums and<br />

Products” in the XSLT Cookbook by Sal Mangano (O’Reilly), which is available at flylib.com/<br />

books.php?ln=en&n=2&p=765&c=45&p1=1&c1=1&c2=208&view=1.<br />

In this exercise, you use the Insert Formula dialog box and amend the XSLT code in Code<br />

view to correct two group totals that have a value of NaN.<br />

SET UP Using SharePoint Designer, open the site you used in the previous exercise<br />

if it is not already open, and then open CreateDVWP.aspx in edit mode with the<br />

SalesReport DFWP selected.<br />

Formula<br />

1. In the List Price column, click NaN, and then on the Options tab, click Formula.<br />

Tip You may have to click NaN again to highlight it.<br />

The Insert Formula dialog box opens, and in the Edit The XPath Expression box, the<br />

formula sum($nodeset/@ListPrice) is displayed. If the formula is not displayed, close<br />

the Insert Formula dialog box and repeat step 1.<br />

2. Place the insertion point between Price and ), and then type a period (.). Click OK.<br />

The Insert Formula dialog box closes, and NaN is replaced by 760.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!