Ich habe folgende XML-DateiXSLT-Transformation der Daten in Tabelle incompleteXML
<root>
<entries>
<entry>
<id>1</id>
<title>entry A</title>
<group>1</group>
<category>a</category>
</entry>
<entry>
<id>2</id>
<title>entry B</title>
<group>1</group>
<category>c</category>
</entry>
<entry>
<id>3</id>
<title>entry C</title>
<group>2</group>
<category>b</category>
</entry>
<entry>
<id>4</id>
<title>entry D</title>
<group>2</group>
<category>c</category>
</entry>
<entry>
<id>5</id>
<title>entry E</title>
<group>3</group>
<category>a</category>
</entry>
<entry>
<id>6</id>
<title>entry F</title>
<group>4</group>
<category>c</category>
</entry>
</entries>
<groups>
<group id="1">
<title>Group 1</title>
</group>
<group id="2">
<title>Group 2</title>
</group>
<group id="3">
<title>Group 3</title>
</group>
<group id="4">
<title>Group 4</title>
</group>
</groups>
<categories>
<category id="a">
<title>A</title>
</category>
<category id="b">
<title>B</title>
</category>
<category id="c">
<title>C</title>
</category>
</categories>
</root>
die Tabellendefinition enthält (Knotengruppen entspricht Zeilen und Kategorieknoten entspricht Spalten) und Tabelleneinträge. Jeder Eintrag wird durch die Gruppen- und Spalten-ID identifiziert, und die Einträge sind nicht für alle Zellen definiert.
Ich brauche als Ausgabe eine Tabelle, wie dieser:
<table>
<thead>
<tr>
<th>Groups</th>
<th>A</th>
<!-- category name -->
<th>B</th>
<!-- category name -->
<th>C</th>
<!-- category name -->
</tr>
</thead>
<tbody>
<tr>
<th group-id="1">Group 1</th>
<!-- group name -->
<th group-id="1" category-id="a"><span>entry A</span></th>
<th group-id="1" category-id="b"></th>
<th group-id="1" category-id="c"><span>entry B</span></th>
</tr>
<tr>
<th group-id="3">Group 2</th>
<!-- group name -->
<th group-id="2" category-id="a"></th>
<th group-id="2" category-id="b"><span>entry C</span></th>
<th group-id="2" category-id="c"><span>entry D</span></th>
</tr>
<tr>
<th group-id="3">Group 3</th>
<!-- group name -->
<th group-id="3" category-id="a"><span>entry E</span></th>
<th group-id="3" category-id="b"></th>
<th group-id="3" category-id="c"></th>
</tr>
<tr>
<th group-id="4">Group 4</th>
<!-- group name -->
<th group-id="4" category-id="a"></th>
<th group-id="4" category-id="b"></th>
<th group-id="4" category-id="c"><span>entry F</span></th>
</tr>
</tbody>
</table>
, die mit leeren Spannweiten alle Zellen der Tabelle füllen würde, wenn es keine Daten in ersten xml sind .
Jede Hilfe wird geschätzt!
Nun, für Ihre Zeilen möchten Sie zum Beispiel ' ... xsl: for-each-group>' und der Inhalt jedes 'tr', das Sie ausfüllen von Ihrem bekannten ' ' entweder mit ' xsl: for-each> 'oder mit ähnlichen Anwendungsvorlagen. –
Hallo! Danke für Ihre Antwort! ... xsl: for-each-group> könnte gut funktionieren, wenn ich alle Gruppen abgedeckt hätte durch Einträge. Es kann einige leere Gruppen geben, ohne dass ein Eintrag vorhanden ist. –
oachkatzlschwoaf
Ich habe gerade versucht, das zusammen bei http://xsltransform.net/bEzjRKP zu geigen, zumindest für das gepostete Sample scheint es der Ansatz funktioniert. Sie können natürlich auch 'groups/group' verarbeiten, um die' tr' Zeilen im Tabellenkörper zu erzeugen und mit einem Schlüssel auf die entsprechenden 'entry' Elemente zuzugreifen. –