1

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.

4

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>
3

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy