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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:50:20+00:00 2026-05-25T23:50:20+00:00

I want to define a variable named ‘category’ in XSL, assign a value to

  • 0

I want to define a variable named ‘category’ in XSL, assign a value to it, and reuse that variable a bit down in my code.
if objecttype=1 the variable value should be ‘car’
if objecttype=2 the variable value should be ‘bus’

How can I achieve that?

<xsl:template match="/">
<html>
<head><style type="text/css">body{font-size:11px;font-family:Verdana;}</style></head>
<body>
Dear
<xsl:for-each select="user">
<xsl:value-of select="firstname"/><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:if test="middlename != ''"> 
<xsl:value-of select="middlename"/><xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:value-of select="user/lastname"/>,<br/>
<br/>
You have created a company listing for "<xsl:value-of select="user/objecttitle"/>".<br/>
<br/>
Did you know Google uses the number of Facebook 'likes' for webpages in its rankings?<br/>
You can like you page here: 
<xsl:for-each select="user"> 
<xsl:variable name="category"> 
    <xsl:choose> 
        <xsl:when test="objecttype='1'">car</xsl:when> 
        <xsl:when test="objecttype='2'">bus</xsl:when> 
    </xsl:choose> 
</xsl:variable> 
</xsl:for-each> 
<a href="http://www.mydomain.com/{$category}/{user/objectid}/{user/objecturl}">Click here to go to your company listing now.</a><br/>
Kind regards,<br/>
<br/>
<br/>
</body>
</html>
</xsl:template>
  • 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-25T23:50:21+00:00Added an answer on May 25, 2026 at 11:50 pm

    This is a common error for XSL newcomers. The correct approach is:

    <xsl:variable name="category">
      <xsl:choose>
        <xsl:when test="objecttype='1'">car</xsl:when>
        <xsl:when test="objecttype='2'">bus</xsl:when>
        ... etc
      </xsl:choose>
    </xsl:variable>
    

    In your example, the variable is local to the <xsl:when...> tag.

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

Sidebar

Related Questions

I want to define some member variable and some code just in Debug Mode,
I want to define a class method that has access to a local variable.
I want to define a ref type variable, like this: SomeType v=null; and this
I want to define a JavaScript class, Foo. Foo = function(value){ this.value = value;
I want to force a class to define a certain variable from the class
If you have a Java variable named xyz. Then later on I define a
I define Sql_Cmd And Other sql variable that need before and Now write this
I want to automatically define incrementing variable names. So instead of this: $Var1 =
I want to defined a variable/parameter in CSS and access it by javascript. What
I want to find the physical address of a variable defined in a user-space

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.