0
votes

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
Hi Oliver, once page is rendered,using developer tool check if url is blank or url contains some garbage characters somewhere at the beginning.Vaibhav
This is the output it creates. The url is black (ie there is not image tag created):<li class="dfwp-item"> <div class="groupheader item medium">Visible Name</div> <ul class="dfwp-list"> <li class="dfwp-item"> <div class="item" /> </li> </ul> </li>user2781156
This is the output when the image displays correctly:<li class="dfwp-item"> <div class="groupheader item medium">Name</div> <ul class="dfwp-list"> <li class="dfwp-item"> <div class="item"><a href="path/to/item"><img class="image customstyle-img" src="path/to/image" title="" /></a></div> </li> </ul> </li>user2781156
There doesn't seem to be any garbage characters in the image url, looks pretty standard to me...user2781156
I missed out on the part "the code works most of the time". This is strange behavior. There are few things you can try.. 1. Remove rest of the tags and only load image URLs and see if it works correctly. 2. Once you are able to load image urls successfully.. try to load them inside image tag and see it works on every page load.. 3. Try deleting browser cache once.. You never know :DVaibhav

1 Answers

0
votes

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>