我在Umbraco宏中生成了一个菜单:
<xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $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 <= $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 <= $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 > 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>
答案 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 <= $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 <= $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 > 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>