Hi all,
I have got the following issue, which I do not get resolved:
I have a source XML document containing the following structure (just an extract):
|
XML Code
|
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
|
<root>
<records>
<record>
<attribA>A</attribA>
<attribB>A</attribB>
<attribC>A</attribC>
<attribD>A</attribD>
<attribE>A</attribE>
<user>
<id>UserA</id>
<roles>
<role>
<system>
<sysname>ABC</sysname>
<sysattr1>A</sysattr1>
<sysattr2>B</sysattr2>
<sysattr3>C</sysattr3>
</system>
</role>
<role>
<system>
<sysname>ABC</sysname>
<sysattr1>A</sysattr1>
<sysattr2>B</sysattr2>
<sysattr3>C</sysattr3>
</system>
</role>
<role>
<system>
<sysname>XYZ</sysname>
<sysattr1>X</sysattr1>
<sysattr2>Y</sysattr2>
<sysattr3>Z</sysattr3>
</system>
</role>
<role>
<system>
<sysname>DEF</sysname>
<sysattr1>D</sysattr1>
<sysattr2>E</sysattr2>
<sysattr3>F</sysattr3>
</system>
</role>
</roles>
</user>
<user>
<id>UserB</id>
<roles>
<role>
<system>
<sysname>ABC</sysname>
<sysattr1>A</sysattr1>
<sysattr2>B</sysattr2>
<sysattr3>C</sysattr3>
</system>
<system>
<sysname>XYZ</sysname>
<sysattr1>X</sysattr1>
<sysattr2>Y</sysattr2>
<sysattr3>Z</sysattr3>
</system>
</role>
<role>
<system>
<sysname>DEF</sysname>
<sysattr1>D</sysattr1>
<sysattr2>E</sysattr2>
<sysattr3>F</sysattr3>
</system>
</role>
</roles>
</user>
</record>
</records>
</root>
|
What I need to have is a unique node list, containing all systems with the same name exactly once. Therefore I created a for-each loop as follows:
|
XML Code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<xsl:template match="/root/records/record">
<xsl:for-each select="user/roles/role/system">
<xsl:sort select="sysname" />
<!-- Problem is, that I now get the following node list concerning "sysname":
ABC
ABC
ABC
XYZ
XYZ
DEF
DEF
But to continue with this information in another section, I want to skip
the duplicates. Therefore I wanted to compare the current element with the
previous one. Using preceding-sibling, following-sibling, etc. does not work.
-->
</xsl:for-each>
</xsl:template>
|
So my question is: How can I reduce the list to only have each entry seperatly and
still access to all tag values below <system>
I tried several things using preceding-sibling, etc. but it does not work. Also after sorting I could remeber the last one, but since I cannot change the value of a defined valriable, this does not work. So basically the question is when I loop through the structure ... how can I skip a a "node" which was already used in the previous loop step.
Your help is highly appreciated !!!
Thanks in advance,
Steffen