Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 290327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:59:15+00:00 2026-05-12T05:59:15+00:00

I working on a site which some if/or statements in XSL and being a

  • 0

I working on a site which some if/or statements in XSL and being a little unfamilar with the language i’m not certain how to accomplish:

if [condion one is met] or [condition two is met] then do [action] otherwise do [alternative action]

can anyone offer some examples?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:59:15+00:00Added an answer on May 12, 2026 at 5:59 am

    Conditionals in XSLT are either an unary “if”:

    <xsl:if test="some Boolean condition">
      <!-- "if" stuff (there is no "else" here) -->
    </xsl:if>
    

    or more like the switch statement of other languages:

    <xsl:choose>
      <xsl:when test="some Boolean condition">
        <!-- "if" stuff -->
      </xsl:when>
      <xsl:otherwise>
        <!-- "else" stuff -->
      </xsl:otherwise>
    </xsl:choose>
    

    where there is room for as many <xsl:when>s as you like.

    Every XPath expression can be evaluated as a Boolean according to a set of rules. These (for the most part) boil down to “if there is something -> true” / “if there is nothing -> false“

    • the empty string is false
    • 0 is false (so is NaN)
    • the empty node set is false
    • the result of false() is false
    • every other literal value is true (most notably: 'false' is true and '0' is true)
    • the result of expressions is evaluated with said rules (no surprise here)

    Edit: There is of course a more advanced (and more idiomatic) method to control program flow, and that’s template matching:

    <xsl:template match="node[contains(., 'some text')]">
      <!-- output X -->
    </xsl:template>
    
    <xsl:template match="node[not(contains(., 'some text'))]">
      <!-- output Y -->
    </xsl:template>
    
    <xsl:template match="/">
      <xsl:apply-templates select=".//node" />
    </xsl:template>
    

    Writing templates that match specific nodes and using <xsl:apply-templates> to make the XSLT processor choose the appropriate ones is superior to writing complex <xsl:if> or <xsl:choose> constructs.

    The above sample is equivalent to the imperative style:

    <xsl:template match="/">
      <xsl:for-each select=".//node">
        <xsl:choose>
          <xsl:when test="contains(., 'some text')">
            <!-- output X -->
          </xsl:when>
          <xsl:when test="not(contains(., 'some text'))">
            <!-- output Y -->
          </xsl:when>
        <xsl:choose>
      <xsl:for-each>
    </xsl:template>
    

    XSLT beginners tend to pick the latter form for its familiarity, but examining template matching instead of using conditionals is worthwhile. (also see.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question. I working on one site on Asp.Net, which uses some
I had a working Rails site which I did not touch for some time.
I am working on a site which has some Norwegian words. When I used
I'm working on a site which has some big images etc to show. On
I'm making some site which must be fully unicode. Database etc are working, i
I am working on multilingual site and in which i used some enum and
I am working on a site which builds other sites. Some if it I
I'm working on a site which has line breaks inserted as <br> in some
I'm working on a site which has some pretty awful urls to redirect, for
I'm working on a site which uses the Facebook API to log users in,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.