I have created a custom xslt style to display the news on my website. My issue is that some of my news have a banner and some of them don't. So how do I determine by using XSLT how to display the news with the banner or without it if it doens't have any?

I know what field contains the banner url. So I can imagine I have to loop through my news and then load the display form by the return value from some sort of if-statement that checks if the news has a banner or not.

I'm new to XSLT so how do I do this? Any help is appriciated.

2 Answers 2


Use the xsl:choose block, with an xsl:if test to see if your URL is empty or not.

something like this:

      <xsl:when test="string-length($urlField) = 0">
        // do stuff
        // show nothing

You'll need to use the Xsl:If function to ascertain whether or not the banner has anything in it to display. In the example below, I'm just testing the $SafeImageUrl variable that the content query webpart supplies out of the box.

<xsl:if test="string-length($SafeImageUrl) !=0">
<img class="image" src="{$SafeImageUrl}" title="@ImageUrlAltText"></img>

Deconstructing the ItemStyle.xsl and other xslt sheets from SharePoint is a great way to learn how to do it, along with sites such as w3schools for their individual tutorials.


  • i think you need {} around the attribute too? {@ImageUrlAltText} Commented Mar 2, 2011 at 14:33
  • Yes you do..well spotted, I was typing from my notebook.. 8-)
    – Cimares
    Commented Mar 4, 2011 at 15:00

Your Answer

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