我正在尝试使用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>