SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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
share|improve this answer

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.


share|improve this answer
i think you need {} around the attribute too? {@ImageUrlAltText} – Anders Rask Mar 2 '11 at 14:33
Yes you do..well spotted, I was typing from my notebook.. 8-) – Cimares Mar 4 '11 at 15:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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