XSLT <xsl:for-each>
❮ XSLT 요소 참조
정의 및 사용
<xsl:for-each> 요소는 지정된 노드 세트의 각 노드를 순환합니다.
통사론
<xsl:for-each
select="expression">
<!-- Content -->
</xsl:for-each>
속성
Attribute | Value | Description |
---|---|---|
select | expression | Required. An XPath expression that specifies which node set to be processed. |
예
아래 예제는 각 cd 요소를 통해 각 cd의 제목을 출력합니다.
예시
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div>
<xsl:for-each select="catalog/cd">
<p><xsl:value-of select="title" /></p>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
아래 예제는 각 cd 요소를 반복하고 각 cd에 대한 제목 및 아티스트의 값으로 테이블 행을 생성합니다.
예시
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Music Collection:</h1>
<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>
❮ XSLT 요소 참조