XSL Tabellentransformation

Ruthgar

Grünschnabel
Hallo.
Ich habe ein kleines Problem beim Transformieren von XML in eine HTML Tabelle.
Via Google und forums-Suchfunktion hab ich leider nur Tutorial gefunden, die mein Problem anhand von Attributen lösen. Leider gibt meine XML-Struktur das nicht her.
Da ich relativ unerfahren in diesem Gebiet bin, bin ich für jhede Hilfestellung dankbar.

Mein XML-File beinhaltet alle benötigten Daten. Jetzt gibt es aber ein Unterscheidungskriterium (ein eigenes Element, KEIN Attribut), zu welchem Bereich die jeweiligen Daten gehören. Pro Bereich soll eine eigene Tabelle erzeugt werden.

Die Erzeugung einer großen Tabelle bekomme ich prima hin, die Gruppierung nach einem bestimmten Kriterium jedoch nicht. :(

Anbei mal der Code aus der XML-Datei :

Code:
<PivotTable>
 <TSData>
  <ts>Alchemy</ts>
  <name>Transmute: Water to Undeath</name>
  <neededItems>1</neededItems>
  <materialcount>1</materialcount>
  <matprice>15495</matprice>
  <sell>96930</sell>
  <spanPercentage>84,01%</spanPercentage>
  <span>81435</span>
 </TSData>
 <TSData>
  <ts>Alchemy</ts>
  <name>Transmute: Primal Earth to Water</name>
  <neededItems>1</neededItems>
  <materialcount>1</materialcount>
  <matprice>49373</matprice>
  <sell>234177</sell>
  <spanPercentage>78,92%</spanPercentage>
  <span>184804</span>
 </TSData>
<TSData>
  <ts>Blacksmithing</ts>
  <name>Green Iron Hauberk</name>
  <neededItems>5</neededItems>
  <materialcount>29</materialcount>
  <matprice>233067</matprice>
  <sell>249000</sell>
  <spanPercentage>6,40%</spanPercentage>
  <span>15933</span>
 </TSData>
 <TSData>
  <ts>Blacksmithing</ts>
  <name>Heavy Sharpening Stone</name>
  <neededItems>1</neededItems>
  <materialcount>1</materialcount>
  <matprice>809</matprice>
  <sell>832</sell>
  <spanPercentage>2,73%</spanPercentage>
  <span>23</span>
 </TSData>
 <TSData>
  <ts>Blacksmithing</ts>
  <name>Patterned Bronze Bracers</name>
  <neededItems>2</neededItems>
  <materialcount>7</materialcount>
  <matprice>12454</matprice>
  <sell>12720</sell>
  <spanPercentage>2,09%</spanPercentage>
  <span>266</span>
 </TSData>
</PivotTable>

Das Gruppierungskriterium ist hier das Element "<ts>". Für jedes "<ts>" brauche ich eine eigene Tabelle.

Mein XSL-Stylesheet sieht wie folgt aus :

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" version="4.01" encoding="ISO-8859-1"/>

<xsl:template match="/">
<xsl:result-document href="ts.html">
	<html>
	<head>
	<link rel="stylesheet" type="text/css" href="style.css" />
	</head>
	<body>
	<table border="1" class="timedata">
	<th>Tradeskill</th>
	<th>Name</th>
	<th>Anz. ben. Materialien</th>
	<th>Materialien</th>
	<th>Materialpreis</th>
	<th>Verkaufspreis</th>
	<th>Gewinnspanne</th>
	<th>Gewinn</th>
	<xsl:apply-templates/>
	</table>
	</body>
	</html>
</xsl:result-document>
</xsl:template>

<xsl:template match="TSData">
	<tr>
	 <xsl:apply-templates select="ts"/>
	 <xsl:apply-templates select="name"/>
	 <xsl:apply-templates select="neededItems"/>
	 <xsl:apply-templates select="materialcount"/>
	 <xsl:apply-templates select="matprice"/>
	 <xsl:apply-templates select="sell"/>
	 <xsl:apply-templates select="spanPercentage"/>
	 <xsl:apply-templates select="span"/>
	</tr>
</xsl:template>


<xsl:template match="ts">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="name">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="neededItems">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="materialcount">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="matprice">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="sell">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="spanPercentage">
	<td><xsl:value-of select="." /></td>
</xsl:template>
<xsl:template match="span">
	<td><xsl:value-of select="." /></td>
</xsl:template>

</xsl:stylesheet>

Es transformiert auch wunderbar... nur eben in eine Tabelle :(

Hat jemand nen vorschlag, wie ich die Daten nach dem Inhalt von "<ts>" gruppieren kann und dann pro Gruppe eine eigene Tabelle erzeugen kann?

Danke für jede Hilfe :)
 
mit <xsl:apply-templates select="//TSData"/>
kann mann das tag auch angeben
und dort die Tabelle angeben






Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" indent="yes" version="4.01" encoding="ISO-8859-1"/>

	<xsl:template match="/">
<xsl:result-document href="ts.html">
		<html>
			<head>
				<link rel="stylesheet" type="text/css" href="style.css"/>
			</head>
			<body>

				<xsl:apply-templates select="//TSData"/>
			</body>
		</html>
		</xsl:result-document>
	</xsl:template>

	<xsl:template match="TSData">
		<h1>
			<xsl:value-of select="position()"/>
		</h1>
		<table border="1" class="timedata">
			<th>Tradeskill</th>
			<th>Name</th>
			<th>Anz. ben. Materialien</th>
			<th>Materialien</th>
			<th>Materialpreis</th>
			<th>Verkaufspreis</th>
			<th>Gewinnspanne</th>
			<th>Gewinn</th>
			<tr>
				<xsl:apply-templates select="ts"/>
				<xsl:apply-templates select="name"/>
				<xsl:apply-templates select="neededItems"/>
				<xsl:apply-templates select="materialcount"/>
				<xsl:apply-templates select="matprice"/>
				<xsl:apply-templates select="sell"/>
				<xsl:apply-templates select="spanPercentage"/>
				<xsl:apply-templates select="span"/>
			</tr>
		</table>
	</xsl:template>


	<xsl:template match="ts">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="name">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="neededItems">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="materialcount">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="matprice">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="sell">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="spanPercentage">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
	<xsl:template match="span">
		<td>
			<xsl:value-of select="."/>
		</td>
	</xsl:template>
</xsl:stylesheet>
 
Zurück