Reputation: 719
Consider the following XML data:
<?xml version="1.0" encoding="UTF-8"?>
<lieferungen>
<artikel id="3526">
<name>apfel</name>
<preis stueckpreis="true">8.97</preis>
<lieferant>Fa. Krause</lieferant>
</artikel>
<artikel id="7866">
<name>Kirschen</name>
<preis stueckpreis="false">10.45</preis>
<lieferant>Fa. Helbig</lieferant>
</artikel>
<artikel id="3526">
<name>apfel</name>
<preis stueckpreis="true">12.67</preis>
<lieferant>Fa. Liebig</lieferant>
</artikel>
<artikel id="7866">
<name>Kirschen</name>
<preis stueckpreis="false">17.67</preis>
<lieferant>Fa. Krause</lieferant>
</artikel>
<artikel id="3526">
<name>apfel</name>
<preis stueckpreis="true">9.54</preis>
<lieferant>Fa. Mertes</lieferant>
</artikel>
<artikel id="7866">
<name>Kirschen</name>
<preis stueckpreis="false">16.45</preis>
<lieferant>Fa. Hoeller</lieferant>
</artikel>
<artikel id="7868">
<name>Kohl</name>
<preis stueckpreis="false">3.20</preis>
<lieferant>Fa. Hoeller</lieferant>
</artikel>
<artikel id="7869">
<name>Kirschen</name>
<preis stueckpreis="false">12.45</preis>
<lieferant>Fa. Richard</lieferant>
</artikel>
<artikel id="3245">
<name>Bananen</name>
<preis stueckpreis="false">15.67</preis>
<lieferant>Fa. Hoeller</lieferant>
</artikel>
<artikel id="6745">
<name>Kohl</name>
<preis stueckpreis="false">3.10</preis>
<lieferant>Fa. Reinhardt</lieferant>
</artikel>
<artikel id="7789">
<name>Ananas</name>
<preis stueckpreis="true">8.60</preis>
<lieferant>Fa. Richard</lieferant>
</artikel>
<artikel id="3225">
<name>Bananen</name>
<preis stueckpreis="false">15.67</preis>
<lieferant>Fa. Schmidt</lieferant>
</artikel>
</lieferungen>
As you can see, there are inconsistencies w.r.t the IDs of the "artikel" (= articles).
For example:
Article "apfel" has id="3526" in line 2 but id="3526" in line 12.
With the following XSLT code I want to display all these inconsistencies:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="lieferungen">
<html>
<head>
<title>Inkonsistenzen</title>
</head>
<body>
<h1>Inkonsistenzen</h1>
<hr/>
<xsl:for-each-group select="artikel" group-by="name">
<p>
<xsl:text> Name: </xsl:text>
<xsl:value-of select="current-grouping-key()"/>
<xsl:variable name="this_id" select="@id"/>
<xsl:text> Lieferant= </xsl:text>
<xsl:value-of select="lieferant"/>
<xsl:text> , ID=</xsl:text>
<xsl:value-of select="$this_id"/>
<xsl:for-each select="current-group()">
<xsl:if test="$this_id != @id">
<xsl:text> Lieferant= </xsl:text>
<xsl:value-of select="lieferant"/>
<xsl:text>; ID=</xsl:text>
<xsl:value-of select="@id"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</p>
</xsl:for-each-group>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The output I get is the following:
Name: apfel Lieferant= Fa. Krause , ID=3526
Name: Kirschen Lieferant= Fa. Helbig , ID=7866 Lieferant= Fa. Richard; ID=7869
Name: Kohl Lieferant= Fa. Hoeller , ID=7868 Lieferant= Fa. Reinhardt; ID=6745
Name: Bananen Lieferant= Fa. Hoeller , ID=3245 Lieferant= Fa. Schmidt; ID=3225
Name: Ananas Lieferant= Fa. Richard , ID=7789
As you can see, my xslt-code worked perfectly fine for all articles except for one: apfel (which is the first article listed in the xml-file). This seems totally crazy to me. Why does my xslt-code work for all items except the first one?
Upvotes: 0
Views: 49