Sandor
Sandor

Reputation: 191

How to only display first node in xsl:when

I have an xsl:when that displays:

What I want is to show all the images but show the category name only once above them since they are all the same for that image set.

Q: How do I accomplish this?

<xsl:for-each select="/data/commissions/entry">
    <xsl:variable name="category-path" select="commission-category"/>

    <xsl:for-each select="imageset/item">               
            <xsl:variable name="image-path" select="image/filename"/>

            <li>
                    <!-- this is the category name --> 
                    <xsl:value-of select="$name-path" />

                    <!-- this is the photo -->
                    <img src="{$image-path}" alt="" />
            </li>
    </xsl:for-each>

Upvotes: 1

Views: 206

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

Move this:

<xsl:value-of select="$name-path" />

before the <xsl:for-each> instruction:

<xsl:for-each select="/data/commissions/entry">
    <xsl:variable name="category-path" select="commission-category"/>

    <!-- this is the category name --> 
    <xsl:value-of select="$name-path" />

    <xsl:for-each select="imageset/item">               
            <xsl:variable name="image-path" select="image/filename"/>

            <li>

                    <!-- this is the photo -->
                    <img src="{$image-path}" alt="" />
            </li>
    </xsl:for-each>

Upvotes: 1

Related Questions