Re: [xsl] Multiple expressions in if conditons

Subject: Re: [xsl] Multiple expressions in if conditons
From: Abel Braaksma <>
Date: Fri, 16 Feb 2007 15:36:43 +0100
Thangavelu Srinivasan wrote:

<xsl:for-each select="//*">

There is hardly ever a reason to use that statement. In all-but-one scenario's you can replace it with:

<xsl:apply-templates select="//*" />

<xsl:template match="*" >
 ...code here ..

Of course, depending on context node, //* may not be desirable at all (it is a very expensive instruction that should be avoided). Every beginner book or tutorial on XSLT should point you to how to use matching templates.

<xsl:variable name="code" select="name()" />

Make sure you understand the differences between using name() and local-name(). This involves understanding namespaces. It is a tricky subject, but once you get the hang of it, it will work to your advantages. Again, I recommend any good text book or online tutorial.

<xsl:variable name="value" select="." />
<xsl:if test= "$code != ('state_results') or ('game_results')">

This is considered 'evil' code (apart from the obvious error). You can do this, of course, but it is far from extensible and hardly ever necessary. See above. Instead, write this for each node you want to match:

<xsl:template match="not(state_results | game_results)" >
  ... your code ...

I am not able to test multiple value using if condition. i want to confirm whether my if conditon is correct for checking multiple value

You can, by joining with 'or'. But, as with any computer language, you must complete your expression.

$code != 'state_results' or $code != 'game_results'

which, by the way, will likely not do what you want: it is always true.

Good luck with learning XSLT. Please read a tutorial, it will save you tons of time. XSLT is not a language like you are likely to be accustomed with, and a tutorial should help you putting on the different pair of glasses needed to work productively and without too many hair-tearing situations ;)

-- Abel Braaksma

Current Thread