Latest web development tutorials

XSLT <xsl : for-each> 요소

<xsl : for-each> 요소 당신은 XSLT에서 루프를 할 수 있습니다.


<xsl : for-each> 요소

XSL <xsl : for-each> 요소는 모든 XML 요소 지정된 노드 세트를 선택할 수 있습니다 :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

»시도

참고 : 선택속성의 값이 XPath 식이다. 이 XPath 식 유사은 슬래시 (/)의 하위 디렉토리를 선택하는 파일 시스템을 찾아 작동합니다.


필터 출력

하여 <xsl : for-each> 요소는 선택 속성 판별을 추가하려면, 우리는 또한 XML 파일 출력 결과를 필터링 할 수 있습니다.

<XSL : 대한-각각 = 선택 "[아티스트 = '밥 딜런'] 카탈로그 / CD를">

합법적 인 사업자 필터 :

  • = (같음)
  • ! = (같지 않음)
  • & 중위 (미만)
  • 한다 (보다)

조정 된 XSL 스타일 시트를 참조하십시오 :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd[artist='Bob Dylan']">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

»시도