・<xsl:for-each>を使い <tr>、<th>、<td>タグを繰り返すことで表を生成する。
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="for_each03.xsl"?>
<root>
<title>パリーグ勝敗表(2000/10/15現在)</title>
<team>
<順位>1位</順位>
<球団名>ダイエー</球団名>
<勝数>73</勝数>
<負数>60</負数>
<勝率>.549</勝率>
</team>
<team>
<順位>2位</順位>
<球団名>西武</球団名>
<勝数>69</勝数>
<負数>61</負数>
<勝率>.531</勝率>
</team>
<team>
<順位>3位</順位>
<球団名>日本ハム</球団名>
<勝数>69</勝数>
<負数>65</負数>
<勝率>.515</勝率>
</team>
<team>
<順位>4位</順位>
<球団名>オリックス</球団名>
<勝数>64</勝数>
<負数>66</負数>
<勝率>.492</勝率>
</team>
<team>
<順位>5位</順位>
<球団名>ロッテ</球団名>
<勝数>61</勝数>
<負数>67</負数>
<勝率>.477</勝率>
</team>
<team>
<順位>6位</順位>
<球団名>近鉄</球団名>
<勝数>58</勝数>
<負数>75</負数>
<勝率>.436</勝率>
</team>
<end>以上です(04/4/5)</end>
</root>
XSLソース
<?xml version="1.0" encoding="Shift_Jis"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Shift_JIS"/>
<xsl:template match="/">
<H4><xsl:value-of select="root/title"/></H4>
<xsl:apply-templates select="root"/>
</xsl:template>
<xsl:template match="root">
<table border="1">
<tr> <!--表の列名は、local-name()関数を使い要素名から取得している-->
<xsl:for-each select="team[1]/*">
<th><xsl:value-of select="local-name()"/></th>
</xsl:for-each>
</tr>
<xsl:for-each select="team">
<tr>
<th><xsl:value-of select="順位"/></th>
<th><xsl:value-of select="球団名"/></th>
<td><xsl:value-of select="勝数"/></td>
<td><xsl:value-of select="負数"/></td>
<td><xsl:value-of select="勝率"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
end(00/10/17、04/4/5修正)