Bonjour à tous,
je chercher à produire un fichier text à partir d'un xml avec xslt. Quelle est la meilleure méthode pour "mettre à plat" un xml ? Je m'explique :
Les noeuds qui n'existent pas doivent être transcrit en caractère de séparation dans mon fichier texte (tab ou ; par exemple)
J'ai le fichier xml suivant (allégé) :
Comment faire avec les otherPersonId pour que lorsqu'ils n'existent pas, j'insère un caractère tab ou ; ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 <eCH0083:record> <eCH0083:attributed> <eCH0083:submittedPersonalAttributes> <eCH0083:localPersonId> <eCH0044:personIdCategory>LOC.RCPers</eCH0044:personIdCategory> <eCH0044:personId>3913471</eCH0044:personId> </eCH0083:localPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CT.VD</eCH0044:personIdCategory> <eCH0044:personId>3913471</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>MU.5586</eCH0044:personIdCategory> <eCH0044:personId>558612356</eCH0044:personId> </eCH0083:otherPersonId> </eCH0083:submittedPersonalAttributes> </eCH0083:attributed> </eCH0083:record> <eCH0083:record> <eCH0083:attributed> <eCH0083:submittedPersonalAttributes> <eCH0083:localPersonId> <eCH0044:personIdCategory>LOC.RCPers</eCH0044:personIdCategory> <eCH0044:personId>3913477</eCH0044:personId> </eCH0083:localPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CT.VD</eCH0044:personIdCategory> <eCH0044:personId>3913477</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CH.ZEMIS</eCH0044:personIdCategory> <eCH0044:personId>5684963180</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>MU.5586</eCH0044:personIdCategory> <eCH0044:personId>558612362</eCH0044:personId> </eCH0083:otherPersonId> </eCH0083:submittedPersonalAttributes> </eCH0083:attributed> </eCH0083:record> <eCH0083:record> <eCH0083:attributed> <eCH0083:submittedPersonalAttributes> <eCH0083:localPersonId> <eCH0044:personIdCategory>LOC.RCPers</eCH0044:personIdCategory> <eCH0044:personId>3913495</eCH0044:personId> </eCH0083:localPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CT.VD</eCH0044:personIdCategory> <eCH0044:personId>3913495</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>MU.5586</eCH0044:personIdCategory> <eCH0044:personId>558612380</eCH0044:personId> </eCH0083:otherPersonId> </eCH0083:submittedPersonalAttributes> </eCH0083:attributed> </eCH0083:record> <eCH0083:record> <eCH0083:attributed> <eCH0083:submittedPersonalAttributes> <eCH0083:localPersonId> <eCH0044:personIdCategory>LOC.RCPers</eCH0044:personIdCategory> <eCH0044:personId>3913507</eCH0044:personId> </eCH0083:localPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CT.VD</eCH0044:personIdCategory> <eCH0044:personId>3913507</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CH.ZEMIS</eCH0044:personIdCategory> <eCH0044:personId>5684963192</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>MU.5586</eCH0044:personIdCategory> <eCH0044:personId>558612391</eCH0044:personId> </eCH0083:otherPersonId> </eCH0083:submittedPersonalAttributes> </eCH0083:attributed> </eCH0083:record> <eCH0083:record> <eCH0083:attributed> <eCH0083:submittedPersonalAttributes> <eCH0083:localPersonId> <eCH0044:personIdCategory>LOC.RCPers</eCH0044:personIdCategory> <eCH0044:personId>3913519</eCH0044:personId> </eCH0083:localPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CT.VD</eCH0044:personIdCategory> <eCH0044:personId>3913519</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>CH.ZEMIS</eCH0044:personIdCategory> <eCH0044:personId>5684963198</eCH0044:personId> </eCH0083:otherPersonId> <eCH0083:otherPersonId> <eCH0044:personIdCategory>MU.5586</eCH0044:personIdCategory> <eCH0044:personId>558612405</eCH0044:personId> </eCH0083:otherPersonId> </eCH0083:submittedPersonalAttributes> </eCH0083:attributed> </eCH0083:record>
Quand ils existent, j'ai besoin du fils personId uniquement, mais pour le test je prend le personIdCategory (plus facile à identifier qu'une suite de chiffres).
Ca doit me produire un texte comme
J'ai commencé ceci mais je suis pas sûr de faire comme il faut, vu que je débute en xslt
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 LOC.RCPers CT.VD MU.5586 LOC.RCPers CT.VD CH.ZEMIS MU.5586 LOC.RCPers CT.VD MU.5586 LOC.RCPers CT.VD CH.ZEMIS MU.5586
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <xsl:template match="/"> <xsl:for-each select="//eCH0083:record"> <xsl:choose> <xsl:when test=".//eCH0044:personIdCategory='LOC.RCPers'"> <xsl:value-of select=".//eCH0044:personIdCategory"/><xsl:text>	</xsl:text> </xsl:when> <xsl:otherwise> <xsl:copy-of select='$vide'/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test=".//eCH0044:personIdCategory='CT.VD'"> <xsl:value-of select=".//eCH0083:otherPersonId/eCH0044:personIdCategory"/><xsl:text>	</xsl:text> </xsl:when> <xsl:otherwise> <xsl:copy-of select='$vide'/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test=".//eCH0044:personIdCategory='CH.ZEMIS'"> <xsl:value-of select="./eCH0044:personIdCategory"/><xsl:text>	</xsl:text> </xsl:when> <xsl:otherwise> <xsl:copy-of select='$vide'/> </xsl:otherwise> </xsl:choose> <xsl:text>
</xsl:text> </xsl:for-each> </xsl:template>
J'espère que mes explications sont compréhensibles... merci d'avance si vous pouvez m'indiquer la voie à suivre
Florian
Partager