views:

234

answers:

1

When testing with ..

/xsl/sample rendering.xslt

..which is a simple rendering provided out of the box by Sitecore, I notice that, in the loop that outputs the item's children, all children are included, regardless of whether those items have a version in the current language.

Is this normal? ... And is there a way to force/check the language to ensure only the items we want appear?

+1  A: 

Sitecore items will always coexist across language barriers. This has to do (atleast I believe this is one of the reasons) with the fact that they all inherit from Standard Template, and this template has some fields that are marked "Shared", i.e. implicitly available to any language.

What the item does not have however, is a Version in the current language. Field values will return null.

You can test this yourself by modifying the Sample Rendering.xsl to this:

<xsl:for-each select="item">
  <xsl:value-of select="@name" /> ( <sc:text field="title" /> )
  <br />
</xsl:for-each>

I ran a quick test, and this was my result. Sample Item 3 is created in non-context language.

Sitecore Welcome to Sitecore

Sample Item 1 ( Sample Item 1 ) Sample Item 2 ( Sample Item 2 ) Sample Item 3 ( )

Mark Cassidy
That is what I had thought, thanks for the confirmation. This also means that I will need to use a .NET control to check for the language version in order to successfully hide children from the menu. That is quite a limitation of xslt.. makes it semi-useless in a multilingual environment. Dang.
misteraidan
Actually - I'm just thinking about it wrong. You can simply add a field such as "AppearInNav" which you can use to show/hide items for particular languages. Not as neat as just displaying if the language exists, but it's pretty standard to need a field such as this anyway. I'll stop hacking on xslt now and just use my noggin a bit more.
misteraidan
I came to such a conclusion myself, just recently. Sometimes thinking outside of the box in Sitecore is really quite helpful. That field you mention makes things a lot easier than trying to do it any other way as you may have found.
dhulk
There's an easier way - in your loop, just loop through items where the field ('title' in this example) is not empty:xsl:for-each select="item[sc:fld('title',.) != '']"
adam