Index
Calculation
Tutorial Videos
Tutorial videos are available here.
Knowledge Base
Visit our User Forum for discussions & solutions
Why do my calculations not work? (Part 2)
As explained in Part 1, calculations are quite straightforward in XpressDox, but there are some things to watch out for. The Part 1 recipe covered the principle of using the correct arithmetic operators, specifically that the division operator is not ‘/’ but is ‘div’. The best practice of surrounding all arithmetic operators with at least one space was also suggested (to overcome problems related to XML allowing a hyphen/minus sign to be part of a data element name).
There is another reason that calculations won’t work, and that is because of a rather finicky rule of XSLT (remember that XpressDox uses XSLT to perform many of its operations). This rule says that a data element to be used in a calculation must consist only of numeric digits, with an optional decimal point, and optionally preceded by a plus or minus sign. Which is fine as it goes, but the template author is not always in command of how data elements are constructed (e.g. they may come from a data base), where the numeric data may be formatted with, for example, thousands separators. Or the data may even be formatted with decimal commas instead of decimal points, some data elements may be empty, etc.
XpressDox provides the function RenderAsNumeric to help with this.
RenderAsNumeric makes sure that the data element value passed to it is rendered as the kind of numeric that XSLT would like. See the article in the Reference about how this works.