Ik probeer wat voor elkaar te krijgen met XSLT maar volgens mij beheers ik het nog niet zo goed want ik snap het niet meer.
Ik heb hieronder een voorbeeld weergegeven van de XML data:
Ik gebruik hiervoor de volgende XSLT
En ik krijg dan het volgende resultaat:
Wat ik eigelijk wil is dat er per family een overzicht komt welke achternamen er in voorkomen en dan per achternaam de verschillende voornamen.
Ik heb hieronder een voorbeeld weergegeven van de XML data:
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
| <records> <family id="1"> <contact id="0001"> <title>Mr</title> <forename>John</forename> <surname>Smith</surname> </contact> <contact id="0001"> <title>Mr</title> <forename>Jom</forename> <surname>Smith</surname> </contact> <contact id="0002"> <title>Dr</title> <forename>Amy</forename> <surname>Jones</surname> </contact> </family> <family id="2"> <contact id="0010"> <title>Mr</title> <forename>John</forename> <surname>Joker</surname> </contact> <contact id="0011"> <title>Mr</title> <forename>Jom</forename> <surname>Joker</surname> </contact> <contact id="0012"> <title>Dr</title> <forename>Amy</forename> <surname>Jones</surname> </contact> </family> <family id="3"> <contact id="0020"> <title>Mr</title> <forename>John</forename> <surname>Jones</surname> </contact> <contact id="0021"> <title>Mr</title> <forename>John1</forename> <surname>Smith</surname> </contact> <contact id="0023"> <title>Dr</title> <forename>Frank2</forename> <surname>Another</surname> </contact> </family> </records> |
Ik gebruik hiervoor de volgende XSLT
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
34
| <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"> <xsl:output version="1.0" encoding="UTF-8" indent="no" omit-xml-declaration="no" media-type="text/html"/> <xsl:key name="contacts-by-surname" match="contact" use="surname" /> <xsl:template match="family"> <html> <head> <title></title> </head> <body> <table border="1"> <tbody> <xsl:for-each select="contact[count(. | key('contacts-by-surname', surname)[1]) = 1]"> <xsl:sort select="surname" /> <tr> <td> <xsl:value-of select="surname" /> from family <xsl:value-of select="../@id" /><br /> </td> <td> <xsl:for-each select="key('contacts-by-surname', surname)"> <xsl:sort select="forename" /> <xsl:value-of select="forename" /> (<xsl:value-of select="title" />) from family <xsl:value-of select="../@id" /><br /> </xsl:for-each> </td> </tr> </xsl:for-each> </tbody> </table> </body> </html> </xsl:template> </xsl:stylesheet> |
En ik krijg dan het volgende resultaat:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| Jones from family 1 Amy (Dr) from family 1 Amy (Dr) from family 2 John (Mr) from family 3 Smith from family 1 John (Mr) from family 1 John1 (Mr) from family 3 Jom (Mr) from family 1 Joker from family 2 John (Mr) from family 2 Jom (Mr) from family 2 Another from family 3 Frank2 (Dr) from family 3 |
Wat ik eigelijk wil is dat er per family een overzicht komt welke achternamen er in voorkomen en dan per achternaam de verschillende voornamen.
[ Voor 0% gewijzigd door RobIII op 28-11-2006 19:23 . Reden: Code=XML toegevoegd, is wat leesbaarder ;) ]