for-each で入れ子ができるかやってみた。
sample.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?xml version="1.0" encoding="Shift_JIS" ?> <?xml-stylesheet type="text/xsl" href="sample.xsl"?> <people> <person> <name>Kevin Shields</name> <work year="1988">isn't anything</work> <work year="1991">loveless</work> </person> <person> <name>Trent Reznor</name> <work year="1989">pretty hate machine</work> <work year="1992">broken</work> <work year="1994">the downward spiral</work> <work year="1999">the fragile</work> <work year="2002">and all that could have been</work> </person> <person> <name>hoge hoge</name> <work year="1988">111</work> <work year="1991">222</work> <work year="2000">333</work> <work year="2015">555</work> </person> <person> <name>huga huga</name> <work year="1989">aaa</work> <work year="1992">bbb</work> <work year="1994">ccc</work> <work year="1999">ddd</work> <work year="2002">eee</work> </person> </people> |
sample.xsl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?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" /> <xsl:template match="/"> <html> <head> <title>XMLとXSLT</title> </head> <body> <p>for-each 入れ子 TEST</p> <xsl:for-each select = "/people/person"> <div> *** <xsl:value-of select="name"/> *** <br /> <xsl:for-each select="./work"> <xsl:value-of select="@year"/>: <xsl:value-of select="."/><br /> </xsl:for-each> <br /> </div> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> |