xsslt를 사용하여 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>