我正在嘗試使用xslt在Sitecore網站中創建一個簡單的項目清單。問題是,我無法找到一種方法來測試某件物品是否具有其下的後代物品。測試子項目
可以很容易地到達頂級這樣設置:
<xsl:template match="*" mode="main">
<table width="100%" class="alternating">
<xsl:for-each select="./item">
<tr>
<td width="100px"><sc:image field="Image" mh="100" mw="100" /></td>
<td style="vertical-align:top"><h2><sc:text field="Title"/></h2></td>
<td style="vertical-align:top"><xsl:value-of select="sc:path(.)" /></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
這在主圖像,標題和每個項目的僅低於你的地方開始路徑的一個不錯的,平坦的桌面。問題是我找不到一種方法來輕鬆測試這些物品中是否有後代。這將使代碼看起來像這樣:
<xsl:template match="*" mode="main">
<table width="100%" class="alternating">
<xsl:for-each select="./item">
<tr>
<td width="100px"><sc:image field="Image" mh="100" mw="100" /></td>
<td style="vertical-align:top"><h2><sc:text field="Title"/></h2></td>
<td style="vertical-align:top"><xsl:value-of select="sc:path(.)" /></td>
<td>
<!—test whether the item has descendants -->
<xsl:if test=?????>
<!—loop through descendant items -->
<xsl:for-each select="./item">
Render information about each descendant item
</xsl:for-each>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>