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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:23:19+00:00 2026-05-30T01:23:19+00:00

<xsl:template match=/> <xsl:variable name=a select=’a’/> <xsl:variable name=b select=’b’/> <xsl:variable name=c select=’c’/> <xsl:variable name=result> <xsl:choose>

  • 0
<xsl:template match="/">
      <xsl:variable name="a" select="'a'"/>
      <xsl:variable name="b" select="'b'"/>
      <xsl:variable name="c" select="'c'"/>
      <xsl:variable name="result">
        <xsl:choose>
          <xsl:when test="$a !=''">
            <xsl:value-of select="$a"/>
          </xsl:when>
          <xsl:when test="$b !=''">
            <xsl:value-of select="$b"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$c"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

The result variable is populated, here i used the xsl choose statements. I just wanted to know if there is any other efficient or simple way to populate the result variable, based on the same logic as xsl choose.

Something like this

<xsl:variable name="result" select="$a | $b | $c" />

The above will work for nodesets, not for variables. Any inputs?xsl 1.0

  • 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-30T01:23:21+00:00Added an answer on May 30, 2026 at 1:23 am

    Something like this

    <xsl:variable name="result" select="$a | $b | $c" /> 
    

    The above will work for nodesets, not for variables. Any inputs?xsl
    1.0

    This is wrong! The above result variable is defined to contain the union of three node-sets — not just one of them, depending on whether some other(s) of them are empty.

    A correct XPath expression in this case is:

    $a | $b[not($a)] | $c[not($a | $b)]
    

    When These three variables aren’t node-sets but strings and if these string values can have any length (not only length of 1), the corresponding XPath expression is similar:

    concat($a, 
           substring($b, 1 div ($a = '')), 
           substring($c, 1 div (concat($a, $b) = ''))
           )
    

    Here we use the fact that:

    substring($s, $k) is the empty string ''

    whenever

    $k >= string-length($s)
    

    and

    substring($s, 1) = $s
    

    Also:

    1 div false()
    

    is positive Infinity

    (false() is converted to 0 when used in arithmetic operations).

    and by definition

    positive Infinity > $k
    

    for every integer $k.

    Therefore,

    substring($s, 1 div $somethingFalse) = ''
    

    and

    substring($s, 1 div $somethingTrue) = $s
    

    Finally, if it is guaranteed that the three variables $a, $b and $c can have as value only a single character, than we can use just:

    substring(concat($a, $b, $c), 1, 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following isn't working as intended: <xsl:template match=xs:complexType> <xsl:param name=prefix /> <xsl:if test=$prefix='core'> <xsl:variable
The following works for me: <xsl:variable name=core select=document('CoreMain_v1.4.0.xsd') /> <xsl:variable name=AcRec select=document('AcademicRecord_v1.3.0.xsd') /> <xsl:template
How can I retrieve the position of the current Para? <xsl:template match=Para> <xsl:variable name=PositionInDocument
I have the following XSLT macro (in Umbraco) <xsl:param name=currentPage/> <xsl:template match=/> <xsl:apply-templates select=$currentPage/imageList/multi-url-picker
I have XSLT 1.0 code like this: <xsl:key name=enemyItems match=metadata[attributes/metadata_key/@value = 'enemylist'] use=attributes/metadata_refkey/@value/> <xsl:template
<p>Title: <xsl:value-of select=$section_map /></p> Note the above section_map variable is printing value /form/medical-info/question-categories/question-category .
<xsl:template match=foo> matches the foo element in the null namespace. <xsl:template match=*> matches any
What is the best way to include an html entity in XSLT? <xsl:template match=/a/node>
Basically I have a small template that looks like: <xsl:template name=templt> <xsl:param name=filter />
<xsl:template match=element[child]> The above works. What is the real syntax for the following pseudo-syntax?

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.