Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers 2

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:choose>
      <xsl:when test="string-length($urlField) = 0">
        // do stuff
      </xsl:when>
      <xsl:otherwise>
        // show nothing
      </xsl:otherwise>
    </xsl:choose>
share|improve this answer
add comment

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>
</xsl:if>

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.

Paul.

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
add comment

Your Answer

 
discard

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.