XSLT(Umbraco)如果是某种doc类型

时间:2011-11-09 14:20:18

标签: xslt umbraco

我在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中,我想要一个只接受某个doctype的if语句,并生成相应的li / a标签,并在href中插入来自该doctype的param。我唯一能想到的就是这样:

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

其中Redirect是doctype,而$urlRedirect是参数。

忍受我,这是我学习XSLT的第一天

更新: 下面是完整的代码,您可以在上下文中看到它:

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

1 个答案:

答案 0 :(得分: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>