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']) > '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>
After reading in the meanwhile I found out(something that however I knew, mostly) that:
So I have changed my logic a little:
I put all conditions within xsl attribute like this:
So no need of extra temp var.