Sharepoint Content Query webpart not showing image (intermittently)

764 Views Asked by At

In sharepoint I have created a content query webpart that queries a list and displays the title and the ImageURL field in 3 column grid format.

For some very strange reason, the code works most of the time and the image and title displays in a grid as I would like. However, if you refresh the page a few times, the image simply does not get found and inserted into the markup. The title does display all the time.

I have created my own Item Style variable in XSL itemStyles.xsl. Here is my code:

<xsl:template name="customStyle" match="Row[@Style='customStyle']" mode="itemstyle">
      <xsl:variable name="SafeLinkUrl">
          <xsl:call-template name="OuterTemplate.GetSafeLink">
              <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
          </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="SafeImageUrl">
          <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
              <xsl:with-param name="UrlColumnName" select="'ImageURL'"/>
          </xsl:call-template>
      </xsl:variable>
      <div class="item">
          <xsl:if test="string-length($SafeImageUrl) != 0">
                  <a href="{$SafeLinkUrl}">
                    <img class="image customstyle-img" src="{$SafeImageUrl}" title="{@ImageUrlAltText}" />
                  </a>
          </xsl:if>
      </div>
  </xsl:template>

I would be grateful if anybody could offer any suggestions.

Oliver

1

There are 1 best solutions below

0
olv53 On

The out the box code was duplicating the imageURL for some reason. The following code fixed it:

<img class="item_customImage" >
    <xsl:attribute name="src">
        <xsl:value-of select="substring-before(@ImageURL, ',')" />
    </xsl:attribute>
 </img>