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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:40:52+00:00 2026-06-14T12:40:52+00:00

I want to add ‘ , ‘ only when it’s needed I check <xsl:when

  • 0

I want to add ‘,‘ only when it’s needed

I check <xsl:when test="$myvar!=''"> so it will not be like:

,one,two,three

but will be
one,two,three instead

but it says

Variable $myvar has not been declared;

<xsl:variable name="myvar">
    <xsl:for-each select="$header/Packaging[@type='european']/UPCPackagingLevelCode">
        <xsl:choose>
            <xsl:when test="$myvar!=''">
                <xsl:value-of select="concat(',',.)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:variable>
  • 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-06-14T12:40:53+00:00Added an answer on June 14, 2026 at 12:40 pm

    You are indeed trying to use a variable before it is has been declared. You are referring to $myVar in the body of the variable declaration. $myVar won’t actually be declared until after the final closing xsl:variable

    In this case, what you need to solve your problem is make use of the position function to determine if you are positioned on the first UPCPackagingLevelCode element.

    So, instead of doing this….

    <xsl:when test="$myvar!=''">
    

    Do this…

    <xsl:when test="position() > 1">
    

    In fact, you could slightly simplify this, to use xsl:if instead of xsl:choose

    <xsl:if test="position() > 1">
        <xsl:text>,</xsl:text>
    </xsl:if>
    <xsl:value-of select="." />
    

    And if you were using XSLT2.0, you could simplify the whole thing to just this

    <xsl:variable name="myvar">
       <xsl:value-of select="$header/Packaging[@type='european']/UPCPackagingLevelCode"
           separator="," />
    </xsl:variable>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want add two textview with orientation vertical(One below other) in a table row
I want add duplicate keys in map,output like the one below: google:Android,google:Maps,apple:iPod,apple:iPhone,apple:iOS Is it
I want add customized View to ScrollView. In customized View, Only two methods are
I want add my custom sidebar next right column all page. Please check this
hi when i write css or html i found that i want add two
Given Two text Boxes. (TextBox1 & TextBox2), I want add two numbers (using the
I want add days to an NSDate . The approach below is not working.
I want add 12 UITextFields in a UITableViewCell (one text field in each row),
I write a module,and want add it to kernel.It will print a world when
I have 2 lists on one page - http://jsfiddle.net/nalsur/CneTJ/ And now I want add/create

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.