Need help adding if / else statements in XSL markup

Posted on 2011-04-27
Last Modified: 2012-05-11
I need to add some if / else statements to an XSL file.  

I understand that I can do something like this:

    <xsl:for-each select="CATALOG/CD">
            <xsl:if match=".[TOPIC='topic1']">
          <td><xsl:value-of select="TITLE"/></td>
          <td><xsl:value-of select="TOPIC"/></td>

However, .. how would I extend this to have mutiple conditionals, .. and with some "NOT EQUAL TO" operators?

if topic = "topic1" OR topic = "topic2" OR topic = "topic3"

if topic != "topic1" AND topic != "topic2" AND topic != "topic3"

Is this possible somehow?  If so, how?

- Yvan
Question by:egoselfaxis
    LVL 60

    Accepted Solution

    <xsl:if match=".[TOPIC='topic1']">
    is NOT correct

    <xsl:if test="TOPIC='topic1'">
    likely is

    for the rest you can simply do
    <xsl:if test="topic != "topic1" and topic != "topic2" and topic != "topic3"">
    LVL 60

    Expert Comment

    by:Geert Bormans
    I messed up the quotes, inside the test attribute all should ne single quotes

    in XSLT2 you can say

    <xsl:if test="not(topic = ('topic1', 'topic2', 'topic3')">

    Author Comment

    Thanks so much!  Your suggestion worked.

    - Yvan
    LVL 60

    Expert Comment

    by:Geert Bormans

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    dividesSelf challange 15 60
    array6 challenfge 6 49
    How Complex Is This Java Course ? 9 52
    allStar challenge 1 27
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now