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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:56:58+00:00 2026-06-08T10:56:58+00:00

In my xslt template I am having a for-each statement. In that for-each I

  • 0

In my xslt template I am having a for-each statement. In that for-each I am making different conditions. I want to have there a variable of string type which shall contain class attributes that will be assigned to a <li>.

As I am new to xslt please provide me some examples or how can I achieve what I want to do.

Here is a bit of my code so you can see what I am taking about:

<xsl:if test="count($currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'">
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
        <li><xsl:attribute name="class">
                topNavigLi
                page<xsl:number value="position()" format="1" />
                <xsl:if test="@nodeName='Network' ">
                    has_submenu network
                </xsl:if>
            </xsl:attribute>
            <xsl:if test="@id = $currentPage/@id">
                <xsl:attribute name="class">
                    current topNavigLi
                    page<xsl:number value="position()" format="1" />
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="position() = last()">
                <xsl:attribute name="class">
                    last topNavigLi
                    page<xsl:number value="position()" format="1" />
                </xsl:attribute>
            </xsl:if>

            <xsl:if test="@id = $currentPage/@id and position() = last()">
                <xsl:attribute name="class">
                    current last topNavigLi
                    page<xsl:number value="position()" format="1" />
                </xsl:attribute>
            </xsl:if>

It would be much elegant to have a variable and than concatenate to it while doing tests.
I have tried like this but returns nothing.

<xsl:variable name="li_class" select="page"> </xsl:variable>

<xsl:attribute name="class">
    <xsl:value-of select="li_class" /> 
</xsl:attribute>
  • 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-08T10:56:59+00:00Added an answer on June 8, 2026 at 10:56 am

    After reading in the meanwhile I found out(something that however I knew, mostly) that:

    The fact that you need to modify an shows that you are
    not thinking in XSLT.

    XSLT is a functional programming language, which, among other things
    means that there is no way one can change a variable. Variables in a
    functional programming language by definition are immutable.
    Source: http://social.msdn.microsoft.com/Forums/eu/xmlandnetfx/thread/2bf7d238-92d2-4453-a683-4bfb0c667795

    So I have changed my logic a little:
    I put all conditions within xsl attribute like this:

     <xsl:if test="count($currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']) &gt; '0'">
                <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
                    <li>
                        <xsl:attribute name="class">
                            page topNavigLi page<xsl:number value="position()" format="1" />
                            <xsl:if test="@id = $currentPage/@id">
                                current 
                            </xsl:if>
                            <xsl:if test="position() = last()">
                                last
                            </xsl:if>
                            <xsl:if test="@nodeName='Network' ">
                                has_submenu network
                            </xsl:if>
                        </xsl:attribute>
    

    So no need of extra temp var.

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

Sidebar

Related Questions

Using XSLT and XPath 1.0, I have a string I want to escape for
I'm writing an XSLT template that need to output a valid xml file for
I read some XSLT examples and found that code: <xsl:apply-template select=@*|node()/> What does that
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I have an xslt stylesheet that needs to call a C# XSLT extension function
I have the following xslt template: <xsl:template name=with-newlines> <xsl:param name=text /> <fo:block linefeed-treatment=preserve white-space-collapse=false
I need to write an XSLT template to identify a string of numbers. How
First I have to state that I touched XSLT today for the first time
I'm having a problem with including xslt templates. I have a.xslt which includes b.xslt
What I want to get is a XSLT template to turn several XML element

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.