somejkuser
somejkuser

Reputation: 9040

obtaining outer loop value inside inner loop with xslt

Here is my code:

    <xsl:for-each select="/*/hundreds/hundred">
    <div class="page_spacer" />
    <div class="page_section" style="{./style}">
    <h2><xsl:value-of select="./label"/></h2>
    <xsl:value-of select="./descriptiontext" />
    <button onclick="javascript:window.location.href='{./viewalllink}'"><xsl:value-of select="./label" /></button>
    <br/>
    <xsl:for-each select="./contendors/contendor">
        <img class="locationthumb" src="/act/locationthumb/{../locid}"/>
    </xsl:for-each>
    </div>
    </xsl:for-each>

I am trying to obtain the locid value from the first loop of hundreds and use it within the second loop inside the img element. I thought maybe ../locid would insinuate using the parent.

Any help would be greatly appreciated.

Upvotes: 1

Views: 418

Answers (1)

Michael Kay
Michael Kay

Reputation: 163352

Bind it to a variable:

<xsl:for-each select="/*/hundreds/hundred">
  <xsl:variable name="h" select="."/>
    <div class="page_spacer" />
    <div class="page_section" style="{./style}">
    <h2><xsl:value-of select="./label"/></h2>
    <xsl:value-of select="./descriptiontext" />
    <button onclick="javascript:window.location.href='{./viewalllink}'"><xsl:value-of select="./label" /></button>
    <br/>
    <xsl:for-each select="./contendors/contendor">
        <img class="locationthumb" src="/act/locationthumb/{$h/locid}"/>
    </xsl:for-each>
    </div>
    </xsl:for-each>

Upvotes: 1

Related Questions