This example uses a loop to fill a table. Each product has a colour code, which is the column index the colour should appear in, and a colour name.
XML Data:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <group> <record> <name>T-Shirt</name> <ArtNo>102</ArtNo> <Beschreibung>fรผr Damen</Beschreibung> <Merkmale> <Product name = "T-Shirt" ArtNo = "102" Beschreibung = "fรผr Damen"> <Merkmal ColNo = "1" Farbe = "rot"/> <Merkmal ColNo = "2" Farbe = "mauve"/> <Merkmal ColNo = "5" Farbe = "grau"/> <Merkmal ColNo = "6" Farbe = "grรผn"/> <Merkmal ColNo = "8" Farbe = "gelb"/> <Merkmal ColNo = "12" Farbe = "gestreift"/> </Product> </Merkmale> </record> <record> <name>T-Shirt</name> <ArtNo>103</ArtNo> <Beschreibung>fรผr Kinder</Beschreibung> <Merkmale> <Product name = "T-Shirt" ArtNo = "103" Beschreibung = "fรผr Kinder"> <Merkmal ColNo = "1" Farbe = "rot"/> <Merkmal ColNo = "3" Farbe = "blau"/> <Merkmal ColNo = "4" Farbe = "pink"/> <Merkmal ColNo = "5" Farbe = "grau"/> <Merkmal ColNo = "6" Farbe = "grรผn"/> <Merkmal ColNo = "8" Farbe = "gelb"/> <Merkmal ColNo = "9" Farbe = "geringelt"/> <Merkmal ColNo = "11" Farbe = "bunt"/> <Merkmal ColNo = "12" Farbe = "gestreift"/> <Merkmal ColNo = "16" Farbe = "lila"/> </Product> </Merkmale> </record> <record> <name>T-Shirt</name> <ArtNo>104</ArtNo> <Beschreibung>fรผr Mรคdchen</Beschreibung> <Merkmale> <Product name = "T-Shirt" ArtNo = "104" Beschreibung = "fรผr Mรคdchen"> <Merkmal ColNo = "1" Farbe = "rot"/> <Merkmal ColNo = "2" Farbe = "mauve"/> <Merkmal ColNo = "3" Farbe = "blau"/> <Merkmal ColNo = "4" Farbe = "pink"/> <Merkmal ColNo = "6" Farbe = "grรผn"/> <Merkmal ColNo = "8" Farbe = "gelb"/> <Merkmal ColNo = "9" Farbe = "geringelt"/> <Merkmal ColNo = "11" Farbe = "bunt"/> <Merkmal ColNo = "12" Farbe = "gestreift"/> <Merkmal ColNo = "15" Farbe = "orange"/> </Product> </Merkmale> </record> <record> <name>T-Shirt</name> <ArtNo>105</ArtNo> <Beschreibung>fรผr Jungen</Beschreibung> <Merkmale> <Product name = "T-Shirt" ArtNo = "105" Beschreibung = "fรผr Jungen"> <Merkmal ColNo = "1" Farbe = "rot"/> <Merkmal ColNo = "3" Farbe = "blau"/> <Merkmal ColNo = "4" Farbe = "mit Autos"/> <Merkmal ColNo = "5" Farbe = "grau"/> <Merkmal ColNo = "6" Farbe = "grรผn"/> <Merkmal ColNo = "8" Farbe = "gelb"/> <Merkmal ColNo = "9" Farbe = "geringelt"/> <Merkmal ColNo = "11" Farbe = "bunt"/> </Product> </Merkmale> </record> <record> <name>Pullover</name> <ArtNo>201</ArtNo> <Beschreibung>fรผr Damen</Beschreibung> <Merkmale> <Product name = "Pullover" ArtNo = "201" Beschreibung = "fรผr Damen"> <Merkmal ColNo = "7" Farbe = "beige"/> <Merkmal ColNo = "10" Farbe = "Olive"/> <Merkmal ColNo = "13" Farbe = "braun"/> </Product> </Merkmale> </record> <record> <name>Pullover</name> <ArtNo>202</ArtNo> <Beschreibung>fรผr Herren</Beschreibung> <Merkmale> <Product name = "Pullover" ArtNo = "202" Beschreibung = "fรผr Herren"> <Merkmal ColNo = "13" Farbe = "braun"/> <Merkmal ColNo = "14" Farbe = "anthrazit"/> </Product> </Merkmale> </record> </group> |
XSL Stylesheet:
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 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="end" select="number(14)" /> <xsl:variable name="increment" select="number(1)"/> <xsl:template match="/"> <table> <xsl:for-each select="//record"> <tr> <xsl:variable name="start" select="number(1)"/> <xsl:call-template name="loop"> <xsl:with-param name="counter" select="$start"/> </xsl:call-template> </tr> </xsl:for-each> </table> </xsl:template> <xsl:template name="loop"> <xsl:param name = "counter"/> <xsl:if test="$counter <= $end"> <td><xsl:value-of select="Merkmale/Product/Merkmal[@ColNo=$counter]/@Farbe"/></td> <xsl:call-template name="loop"> <xsl:with-param name="counter" select="$counter + $increment"/> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> |
Output: