Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT Ternary "If" Operator?

Tags:

xpath

xslt-1.0

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" />
like image 746
swshaun Avatar asked Apr 09 '13 21:04

swshaun


1 Answers

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)

like image 72
Billy ONeal Avatar answered Oct 09 '22 19:10

Billy ONeal