8

I'm trying to pull in custom columns from a SP list, and it works fine, but now I have to figure out how to do a for-each instead since it needs to pull in all items not just one.

Here's where I am so far:

<xsl:template name="forSale" match="Row[@Style='forSale']" mode="itemstyle">
    <div class="wrapper">
        <div id="banner-slide">
            <ul class="bjqs">
                <li><a href="{@FileURL}" />'><img src="{@ThumbnailURL}" title="{@Caption}" /></a></li>
            </ul>
        </div>
    </div>
</xsl:template>

The <li> part is the one I need to do a for-each on. Any ideas how to accomplish this?

EDIT: How about this instead?

SharePoint's ItemStyle template pulls in each row from a list automatically, so how would I pull this piece before the ItemStyle

<div class="wrapper">
        <div id="banner-slide">
            <ul class="bjqs">

And this piece of code after ItemStyle?

</ul>
        </div>
    </div>

This is how my ItemStyle would look then:

<xsl:template name="forSale" match="Row[@Style='forSale']" mode="itemstyle">
    <li><a href="{@FileURL}" />'><img src="{@ThumbnailURL}" title="{@Caption}" /></a></li>
</xsl:template>

3 Answers 3

4
+25

See if this helps:

                  <xsl:for-each select="rows\row">
                    <li>
                      <a>
                        <xsl:attribute name="href">
                          <xsl:value-of select="{@FileURL}" />
                        </xsl:attribute>
                        <xsl:attribute name="src">
                          <xsl:value-of select="{@ThumbnailURL}" />
                        </xsl:attribute>
                        <xsl:attribute name="title">
                          <xsl:value-of select="{@Caption}" />
                        </xsl:attribute>
                      </a>
                    </li>
                  </xsl:for-each>

Please correct the "Rows\Row" as I'm not exactly sure about the list schema.

1
  • Nope that doesn't work either. I had to put src and title within img tag, but it still didn't work. I changed my original post to maybe make it easier.
    – zen
    Dec 17, 2012 at 15:54
3

I was able to do it by modifying the ContentQueryMain.xsl file to insert non-repeating markup before and after content query as shown here.

http://blog.mastykarz.nl/wrapping-contents-content-query-web-part-additional-markup/

1

If your match is correct, do something of the following:

<xsl:for-each select="forSale">
  <li>
    <a href="<xsl:value-of select='FileURL' />">
       <img src="<xsl:value-of select='ThumbnailURL' />" 
            title="<xsl:value-of select='Caption' />" />
    </a>
  </li>
</xsl:for-each>

For more reference, take a look at MSDN <xsl:for-each> Element

4
  • What happens when I do this is that each item gets its own <div class="wrapper"> and it's own ul. In other words, that whole code is repeated, whereas I only need the <li> piece to repeat.
    – zen
    Dec 12, 2012 at 20:26
  • @zen Have you tried to place the foreach statement just including the <li></li> tags, since that's what you want to have repeated?
    – Benny Skogberg
    Dec 12, 2012 at 20:31
  • @zen I need to see the source of FileURL, ThumbnailURL and Caption to know what to select from in my for-each statement...
    – Benny Skogberg
    Dec 12, 2012 at 20:36
  • I added the XML output of that entire SharePoint list. Does that help?
    – zen
    Dec 12, 2012 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.