XSLT Ternary "If" Operator?

xpath, xslt-1.0

Solution

XPath does not support a conditional expression operator. It does, however, support if/then/else syntax if you happen to have an XSLT 2.0 processor. (Note that most XSLT processors do not support this)

Problem

I am making use of XSLT and XML to produce an output document. What I have in the data (in XML form over which I have no control) is the following: ``` <ea type="null"/> <pa type="null"/> <perf>4</perf> ``` I need to use these in calculations. I see that providing a default value for these requires performing a transformation on the document to provide a default value which is a bit long winded. So I thought, does there exist a ternary operation in XPath/XSLT, along the lines of PHP: ``` $result = ($var == null ? true:false) ``` So that the following provides a result (even if it is zero) ``` <xsl:value-of select="ea + pa + perf" /> ```

Original source