2009-12-11 2 views
0

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> 

답변

1

자손을 테스트 할 필요가 없습니다. 그냥 사용하십시오 :

해당 노드에 대한 출력이 없습니다.

0

라쉬 미가 맞습니다. 어린이가 없으면 for-each가 실행되지 않아야합니다.

그러나 부수적으로, 그냥 질문에 대답하기 위해, 당신은 당신이 목록을 렌더링하고 포장 태그를 원하지 않는 경우

<xsl:if test="count(item) != 0"> 
0

당신은 후손을 테스트 할 수있는 테스트를 수행 할 때 때로 믿을 수 ' 어떤 자손이라면 다음을 원할 수 있습니다 :

<xsl:if test="count(./item) &gt; 0"> 
    <ul> 
    <xsl:for-each select="./item"> 
     <li> 
     <!-- content here --> 
     </li> 
    </xsl:for-each> 
    </ul> 
</xsl:if> 
관련 문제