2011-11-09 67 views
1

我有一個一把umbraco宏生成的菜單:XSLT(一把umbraco)如果某些文檔類型

<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] "> 
    <li> 
     <a href="{umbraco.library:NiceUrl(@id)}"> 
     <xsl:value-of select="@nodeName"/> 
     </a>  
    </li> 
</xsl:for-each> 

在這的foreach,我想一個if語句只接受特定的文檔類型,併產生相應的li/a標籤並在href中插入該doctype的參數。我唯一能想到的東西,是這樣的:

 <xsl:if test="$currentPage/Redirect"> 
     <li> 
      <a href="{$urlRedirect)}"> 
       <xsl:value-of select="@nodeName"/> 
      </a> 
     </li> 
     </xsl:if> 

哪裏Redirect是DOCTYPE,並且$urlRedirect是帕拉姆。

多多包涵,這是我第一天學習XSLT

UPDATE: 繼承人的完整代碼,所以你可以看到它在上下文中:

<xsl:template match="/"> 
<!-- The fun starts here --> 
<!-- update this variable on how deep your navigation should be --> 
<xsl:variable name="maxLevel" select="5"/> 
<xsl:variable name="minLevel" select="4"/> 

<xsl:choose> 
    <xsl:when test="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] "> 
    <ul> 
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or 

umbraco.library:HasAccess(@id, @path) = true())] "> 

<!-- Here is where I want my if/else logic --> 

     <li> 
     <a href="{umbraco.library:NiceUrl(@id)}"> 
      <xsl:value-of select="@nodeName"/> 
     </a> 
     </li> 

    </xsl:for-each> 
    </ul> 
    </xsl:when> 
    <xsl:otherwise> 
    <ul> 

     <xsl:for-each select="$currentPage/../* [@level &gt; 3 and @isDoc and string(umbracoNaviHide) != '1' and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] "> 
     <li> 
     <a href="{umbraco.library:NiceUrl(@id)}"> 
      <xsl:value-of select="@nodeName"/> 
     </a> 
     </li> 
    </xsl:for-each> 
    </ul> 
    </xsl:otherwise> 
</xsl:choose> 

</xsl:template> 

回答

2

,你可以做這樣的:

<xsl:template match="/"> 
<!-- The fun starts here --> 
<!-- update this variable on how deep your navigation should be --> 
<xsl:variable name="maxLevel" select="5"/> 
<xsl:variable name="minLevel" select="4"/> 

<xsl:choose> 
    <xsl:when test="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] "> 
    <ul> 
    <xsl:apply-templates select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevel and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())]" /> 
    </ul> 
    </xsl:when> 
    <xsl:otherwise> 
    <ul> 

     <xsl:for-each select="$currentPage/../* [@level &gt; 3 and @isDoc and string(umbracoNaviHide) != '1' and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true())] "> 
     <li> 
     <a href="{umbraco.library:NiceUrl(@id)}"> 
      <xsl:value-of select="@nodeName"/> 
     </a> 
     </li> 
    </xsl:for-each> 
    </ul> 
    </xsl:otherwise> 
</xsl:choose> 

</xsl:template> 

<xsl:template match="*"> 
    <li> 
     <a href="{umbraco.library:NiceUrl(@id)}"> 
       <xsl:value-of select="@nodeName"/> 
     </a>  
     </li> 
</xsl:template> 
<xsl:template match="Redirect"> 
    <li> 
     <a href="{urlRedirect}"> 
      <xsl:value-of select="@nodeName"/> 
     </a> 
    </li> 
</xsl:template> 
+0

感謝您的快速回答。更新。忘了提及,如果它不匹配模板重定向,它應該使用另一個模板。如果它匹配重定向,則不假設使用另一個模板。 –

+0

Pseudo like: random random2 –

+0

@KasperSkov查看我的編輯 – Kimtho6