views:

605

answers:

1

Right now when i'm setting publishing restrictions for items in Sitecore that get rendered by xslt renderings, the xslt will just output empty blocks which don't look very nice on the website.

This is the xslt code i'm using to render my Sitecore item:

      <xsl:for-each select="$item[sc:fld('__created',.)]">
    <xsl:for-each select="sc:Split('Agenda-items',$item)">
      <xsl:variable name="thisitem" select="sc:Split('Agenda-items',$item)" />
      <xsl:variable name="loopitem" select="sc:item(text(),.)" />
      <xsl:if test="$item[sc:fld('__created',.)]">

        <div class="agendaItem">
          <div class="agendaDatum">
            <span class="agendaDag">
              <sc:date field="Begindatum" format="dd" select="$loopitem" />
            </span>
            <span class="agendaMaand">
              <sc:date field="Begindatum" format="MMM" select="$loopitem" />
            </span>
          </div>
          <div class="agendaTekst">
            <sc:link select="$loopitem" title="" class="rood">
              <sc:text field="Titel" select="$loopitem" />
            </sc:link>
            <br />
            <span class="agendaUitleg">
              <xsl:value-of select="stringutil:Clip(sc:field('Intro',$loopitem), 60, 1)"/>&#160;
            </span>
          </div>
        </div>
      </xsl:if>
    </xsl:for-each>
  </xsl:for-each>

What i want is to check wheter an item has a version available in the context language that is NOT restricted from being shown on the current date. So for example:

It's 12 february 2010 and i have an item which is restricted from publishing from 11 february 2010 untill 16 february 2010. Right now it will not be shown, which is what i want. But instead of not Showing my spans and div's either, it will just fill them with empty info. This results in empty blocks on the website which is kind of ugly:

Empty :/

So the top one item of this block shows an item, while it's restricted from being published. How can i handly this in xslt??

The Sitecore presentation xslt cookbook says:

<xsl:for-each select="$sc_currentitem/item[sc:fld('__created',.)]">
<!--the context element is an item with a version in the context language--> 
</xsl:for-each>

This is to select items with a version in the context language, but isn't working for what I want.

+1  A: 

Remember that although the item referred to isn't published a reference to it will still exist in the 'Agenda-items' field in the form of a guid, therefore when you split the field you will have four items to iterate through but only three items in the database.

To ensure that only items that exist in the database are listed add the following if test:

<xsl:for-each select="sc:Split('Agenda-items',$item)">
  <xsl:if test="sc:item(.,.) !=''">
    <xsl:variable name="thisitem" select="sc:Split('Agenda-items',$item)" />
    <xsl:variable name="loopitem" select="sc:item(text(),.)" />
    <!-- other processing -->
  <xsl:if>
</xsl:for-each>
Michael Edwards
But since i don't have something called $sc:item i can't test on that variable. I'm still not having a solution for this problem :/...
Younes
sorry the $sc:item was a mistake it should be sc:item I have ammended
Michael Edwards