Question

I have this piece of XSLT

<xsl:template match="/">

    <xsl:variable name="boxes" select="$currentPage/boxes/descendant::nodeId [text() != '']" />

    <xsl:if test="count($boxes) &gt; 0">

        <div id="boxContainer">

            <ul class="noList" id="frontBoxes">     

            <xsl:for-each select="$boxes">

                <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />                             
                <xsl:variable name="imageNodes" select="umbraco.library:Split($node/descendant::boxImage, ',')" />

                <xsl:for-each select="$imageNodes/descendant::value">
                    <xsl:variable name="image" select="umbraco.library:GetMedia(.,0)" />                                        
                        <li>
                            <a class="boxLink">
                                <xsl:attribute name="href">
                                    <xsl:value-of select="umbraco.library:NiceUrl($node/descendant::boxLink)" />
                                </xsl:attribute>

                                <xsl:value-of select="$node/@nodeName" />
                            </a>

                            <img src="{Eksponent.CropUp:Url($image/umbracoFile, 'frontBoxes')}" width="{$image/umbracoWidth}" height="{$image/umbracoHeight}" alt="" />
                            <xsl:value-of select="$node/descendant::bodyText" />                            
                        </li>
                </xsl:for-each>

            </xsl:for-each>

            </ul>
        </div>
    </xsl:if>

</xsl:template>

If runs through a maximum and minimum of for front page boxes with an image, text and a link.

How can I get the last item so that I can output class="last" in the last <li>

I have tried with <xsl:if test="position()"> inside the last for-each but that doesn't work as intended.

Was it helpful?

Solution

use

<xsl:choose>
    <xsl:when test="position()=last()">
        <!-- set class="list" -->
    </xsl:when>
    <xsl:otherwise>
        <!-- without class="list" -->
    </xsl:otherwise>
</xsl:choose>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top