xsl-list
[Top] [All Lists]

Re: [xsl] Multiple expressions in if conditons

2007-02-16 07:38:26
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:

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

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

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 ...
</xsl:template>


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 ;)

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>