2016-12-21 10 views
0

Я очень новичок в XSLT и пытаюсь редактировать код, который настраивает навигацию для сайта Sitecore. Прямо сейчас, он настроен на получение значения поля «Название меню» и использование этого для навигации на суше. Тем не менее, есть шаблоны, которые не имеют этого поля, поэтому я хотел бы иметь возможность получить значение поля «Заголовок страницы» в этих случаях.XSLT - выберите один из двух полей Sitecore

Я могу делать такие вещи с C#, но XSLT совершенно другой. Какие-либо предложения?

Вот полный XSLT-файл:

<?xml version="1.0" encoding="UTF-8"?> 
<!--============================================================= 
    File: BreadCrumb.xslt                        
    Copyright notice at bottom of file 
==============================================================--> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sc="http://www.sitecore.net/sc" xmlns:dot="http://www.sitecore.net/dot" exclude-result-prefixes="dot sc"> 
    <!-- output directives --> 
    <xsl:output method="html" indent="no" encoding="UTF-8" /> 
    <!-- parameters --> 
    <xsl:param name="lang" select="'en'" /> 
    <xsl:param name="id" select="''" /> 
    <xsl:param name="sc_item" /> 
    <xsl:param name="sc_currentitem" /> 
    <!-- variables --> 
    <!-- Uncomment one of the following lines if you need a "home" variable in you code --> 
    <!--<xsl:variable name="home" select="sc:item('/sitecore/content/home',.)" />--> 
    <!--<xsl:variable name="home" select="/*/item[@key='content']/item[@key='home']" />--> 
    <!--<xsl:variable name="home" select="$sc_currentitem/ancestor-or-self::item[@template='site root']" />--> 
    <!-- entry point --> 
    <xsl:template match="*"> 
    <xsl:apply-templates select="$sc_item" mode="main" /> 
    </xsl:template> 
    <!--==============================================================--> 
    <!-- main--> 

    <xsl:template match="*" mode="main"> 
    <!--==============================================================--> 
    <div class="bread-crumb-box" style="margin-left:auto; margin-right:auto; margin-top: -25px;"> 
     <div class="container" style="width:100%"> 
     <div class="row"> 
      <small style="font-size:12px; float:left"> 
      <a href="/">Home</a> 
      <xsl:for-each select="ancestor-or-self::item"> 
       <xsl:if test="position() &gt; 2 and @template != 'folder' and @template != 'blogtypefolder'"> 
       <xsl:choose> 
        <xsl:when test="position() != last()"> 
        <sc:link class="white"> 
         <xsl:call-template name="GetNavTitle" /> 
        </sc:link> 
        </xsl:when> 
        <xsl:otherwise> 
        <!--<strong>--> 
        <xsl:call-template name="GetNavTitle" /> 
        <!--</strong>--> 
        </xsl:otherwise> 
       </xsl:choose> 
       <xsl:if test="position() != last()"> 
        &gt; 
       </xsl:if> 
       </xsl:if> 
      </xsl:for-each> 
      </small> 
     </div> 
     </div> 
    </div> 
    </xsl:template> 
    <!--This part is what needs to be adjusted, I believe--> 
    <xsl:template name="GetNavTitle"> 
    <xsl:param name="item" select="." /> 
    <xsl:choose> 
     <xsl:when test="sc:fld('navtitle', $item)"> 
     <xsl:value-of select="sc:fld('Menu Title', $item)" /> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:variable name="holder" select="$item/@id" /> 
     <!--<xsl:value-of select="$item/@name" />--> 
     <xsl:value-of select="sc:fld('Menu Title', sc:item($holder,.))" /> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 
</xsl:stylesheet> 
+0

Рефакторинг в C#;) – Gatogordo

+0

мкм. Остальная часть сообщества Sitecore отказалась от XSLT, как 5 лет назад. Или больше. Было бы предложение придерживаться C#, а не пытаться изучить XSLT. –

ответ

1

Ваш XSLT должен быть изменен следующим образом:

<xsl:choose> 
    <xsl:when test="sc:fld('Menu Title', $item) != '' "> 
    <xsl:value-of select="sc:fld('Menu Title', $item)" /> 
    </xsl:when> 
    <xsl:otherwise> 
    <xsl:value-of select="sc:fld('Page Title', $item)" /> 
    </xsl:otherwise> 
</xsl:choose> 
+0

Это решило проблему. Благодаря! –