I am trying to create a simple inventory of items in a Sitecore website using an xslt. The problem is that I can t find a way to test whether an item has descendant items beneath it.
It s easy to get the top level set like this:
<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>
This creates a nice, flat table of the main image, the title and the path of each item just below where you start. The problem is that I can’t find a way to easily test whether one of these items has descendants. That would make the code look something like this:
<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>