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 7576185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:51:39+00:00 2026-05-30T16:51:39+00:00

When I have this in xsl: <xsl:choose> <xsl:when test=something > 0> <xsl:variable name=myVar select=true()/>

  • 0

When I have this in xsl:

<xsl:choose>
  <xsl:when test="something > 0">
    <xsl:variable name="myVar" select="true()"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:variable name="myVar" select="false()"/>
  </xsl:otherwise>
</xsl:choose>

How can I then print out the value of “myVar”? Or more importantly, how can I use this boolean in another choose statement?

  • 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-30T16:51:40+00:00Added an answer on May 30, 2026 at 4:51 pm
    <xsl:choose>
      <xsl:when test="something > 0">
        <xsl:variable name="myVar" select="true()"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="myVar" select="false()"/>
      </xsl:otherwise>
    </xsl:choose>
    

    This is quite wrong and useless, because the variable $myVar goes out of scope immediately.

    One correct way to conditionally assign to the variable is:

    <xsl:variable name="myVar">
      <xsl:choose>
        <xsl:when test="something > 0">1</xsl:when>
        <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    

    However, you really don’t need this — much simpler is:

    <xsl:variable name="myVar" select="something > 0"/>
    
    How can I then print out the value of "myVar"?
    

    Use:

    <xsl:value-of select="$myVar"/>
    

    Or more importantly, how can I use this boolean in another choose
    statement?

    Here is a simple example:

    <xsl:choose>
      <xsl:when test="$myVar">
       <!-- Do something -->
      </xsl:when>
      <xsl:otherwise>
       <!-- Do something else -->
      </xsl:otherwise>
    </xsl:choose>
    

    And here is a complete example:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/*/*">
      <xsl:variable name="vNonNegative" select=". >= 0"/>
    
      <xsl:value-of select="name()"/>: <xsl:text/>
    
      <xsl:choose>
       <xsl:when test="$vNonNegative">Above zero</xsl:when>
       <xsl:otherwise>Below zero</xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the following XML document:

    <temps>
     <Monday>-2</Monday>
     <Tuesday>3</Tuesday>
    </temps>
    

    the wanted, correct result is produced:

     Monday: Below zero
     Tuesday: Above zero
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>
What can I do to make this code work? <xsl:choose> <xsl:when test='type = 6'>
I have an XSL template: <meta name=description content={$page-description}/> and a variable: <xsl:variable name=page-description> <xsl:choose>
I have this xslt : <xsl:param name=total_articles select=3 /> <xsl:param name=articles_per_page select=3 /> <xsl:apply-templates
I have a basic XSLT filter on a SharePoint 2007 DataFormWebPart: <xsl:variable name=Rows select=/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate)
I have this XSLT to create rows according to position in for-each: <xsl:for-each select=Campaign>
I am having this below variable <xsl:variable name=testvar> d e d </xsl:variable> and I
I have an xslt file. In this file, I have an xsl choose statement.
I have two nested loop in XSL like this, at this moment I use
I have this setup where in my development copy I can commit changes on

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.