Bonjour à tous,
Je ne connais pas très bien le langage XSLT et malgré la lecture de quelques cours je n'arrive pas à faire ce dont j'ai besoin.
J'ai en entrée un fichier XML formaté comme suit:
Potentiellement, on peut avoir plusieurs candidats différents dans le fichier XML d'entrée et pour chaque candidats, on a plusieurs "Studies" et "experiences" mais le fichier n'est pas très bien formatté et les ligne de candidates, studies et Experiences peuvent être répétées.
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 <?xml version="1.0" encoding="UTF-8"?> <record> <field name="Number">10080</field> <field name="Process,Progress">100</field> <field name="ProfileInformation,CandidateNumber">10099</field> <field name="ProfileInformation,Candidate,FirstName">Jerry</field> <field name="ProfileInformation,Candidate,LastName">SMITH</field> <field name="ProfileInformation,Candidate,Birthday">1977-04-27T00:00:00</field> <field name="ProfileInformation,Candidate,EmailAddress">jerry.smith@gmail.com</field> <field name="ProfileInformation,Studies,StartDate">1998-04-27T00:00:00</field> <field name="ProfileInformation,Studies,GraduationDate">2000-01-15T00:00:00</field> <field name="ProfileInformation,Studies,OtherInstitutionName">Boston College</field> <field name="ProfileInformation,Experiences,BeginDate">2001-01-01T00:00:00</field> <field name="ProfileInformation,Experiences,EndDate">2006-08-31T00:00:00</field> <field name="ProfileInformation,Experiences,OtherEmployerName">Renault</field> <field name="ProfileInformation,Experiences,OtherJobTitle">Engineer</field> </record> <record> <field name="Number">10021</field> <field name="Process,Progress">100</field> <field name="ProfileInformation,CandidateNumber">10100</field> <field name="ProfileInformation,Candidate,FirstName">John</field> <field name="ProfileInformation,Candidate,LastName">DOE</field> <field name="ProfileInformation,Candidate,Birthday">1979-04-27T00:00:00</field> <field name="ProfileInformation,Candidate,EmailAddress">john.doe@gmail.com</field> <field name="ProfileInformation,Studies,StartDate">1997-04-27T00:00:00</field> <field name="ProfileInformation,Studies,GraduationDate">2000-01-15T00:00:00</field> <field name="ProfileInformation,Studies,OtherInstitutionName">Sorbonne Graduate Business School Université Paris I</field> <field name="ProfileInformation,Experiences,BeginDate">2000-01-01T00:00:00</field> <field name="ProfileInformation,Experiences,EndDate">2004-08-31T00:00:00</field> <field name="ProfileInformation,Experiences,OtherEmployerName">Self employee</field> <field name="ProfileInformation,Experiences,OtherJobTitle">Adviser</field> </record> <record> <field name="Number">10021</field> <field name="Process,Progress">100</field> <field name="ProfileInformation,CandidateNumber">10100</field> <field name="ProfileInformation,Candidate,FirstName">John</field> <field name="ProfileInformation,Candidate,LastName">DOE</field> <field name="ProfileInformation,Candidate,Birthday"1979-04-27T00:00:00/field> <field name="ProfileInformation,Candidate,EmailAddress">john.doe@gmail.com</field> <field name="ProfileInformation,Studies,StartDate">1997-04-27T00:00:00</field> <field name="ProfileInformation,Studies,GraduationDate">2000-01-15T00:00:00</field> <field name="ProfileInformation,Studies,OtherInstitutionName">Sorbonne Graduate Business School Université Paris I</field> <field name="ProfileInformation,Experiences,BeginDate">2004-09-01T00:00:00</field> <field name="ProfileInformation,Experiences,EndDate"/> <field name="ProfileInformation,Experiences,OtherEmployerName">Etat</field> <field name="ProfileInformation,Experiences,OtherJobTitle">Fonctionnaire</field> </record>
Je voudrais faire une transformation de ce fichier selon les règles de gestion suivantes:
- Enlever les deux 1er attributs de "record" qui sont inutiles
- Créer une balise "CANDIDATES", renommer la balise record en CANDIDATE et y insérer les infos correspondantes
- Pour chaque candidat, insérer autant de lignes de studies qu'il y a potentiellement dans le fichier XML pour le candidat (clé candidat= Candidatenumber, clé studies = StartDate)
- Pour chaque candidat, insérer autant de lignes de Experiences qu'il y a potentiellement dans le fichier XML pour le candidat (clé candidat= Candidatenumber, clé Experiences= BeginDate)
Sachant que le fichier XML peut être anarchique: désordre dans l'ordre des candidats, doublons sur le candidatenumber, expériences pouvant être vide puis renseignée plus loin pour un candidat donné etc...
Donc en sortie pour le fichier XML ci dessus, on aurait quelquechose comme:
Merci d'avance pour l'aide apportée.
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 <?xml version="1.0" encoding="UTF-8"?> <CANDIDATES> <CANDIDATE> <CANDIDATENUMBER>10099</CANDIDATENUMBER> <FIRSTNAME>Jerry</FIRSTNAME> <LASTNAME>SMITH</LASTNAME> <BIRTHDAY>1977-04-27T00:00:00</BIRTHDAY> <EMAILADDRESS>jerry.smith@gmail.com</EMAILADDRESS> <STUDIES> <STUDY> <STARTDATE>1998-04-27T00:00:00</STARTDATE> <GRADUATIONDATE>2000-01-15T00:00:00</GRADUATIONDATE> <OTHERINSTITUTIONNAME>Boston College</OTHERINSTITUTIONNAME> </STUDY> </STUDIES> <EXPERIENCES> <EXPERIENCE> <BEGINDATE>2001-01-01T00:00:00</BEGINDATE> <ENDDATE>2003-01-01T00:00:00</ENDDATE> <OTHEREMPLOYERNAME>Renault</OTHEREMPLOYERNAME> <OTHERJOBTITLE>Engineer</OTHERJOBTITLE> </EXPERIENCE> </EXPERIENCES> </CANDIDATE> <CANDIDATE> <CANDIDATENUMBER>10100</CANDIDATENUMBER> <FIRSTNAME>John</FIRSTNAME> <LASTNAME>DOE</LASTNAME> <BIRTHDAY>1979-04-27T00:00:00</BIRTHDAY> <EMAILADDRESS>john.doe@gmail.com</EMAILADDRESS> <STUDIES> <STUDY> <STARTDATE>1997-04-27T00:00:00</STARTDATE> <GRADUATIONDATE>2000-01-15T00:00:00</GRADUATIONDATE> <OTHERINSTITUTIONNAME>Sorbonne Graduate Business School Université Paris I</OTHERINSTITUTIONNAME> </STUDY> </STUDIES> <EXPERIENCES> <EXPERIENCE> <BEGINDATE>2000-01-01T00:00:00</BEGINDATE> <ENDDATE>2004-08-31T00:00:00</ENDDATE> <OTHEREMPLOYERNAME>Self employee</OTHEREMPLOYERNAME> <OTHERJOBTITLE>Adviser</OTHERJOBTITLE> </EXPERIENCE> <EXPERIENCE> <BEGINDATE>2004-09-01T00:00:00</BEGINDATE> <ENDDATE/> <OTHEREMPLOYERNAME>Etat</OTHEREMPLOYERNAME> <OTHERJOBTITLE>Fonctionnaire</OTHERJOBTITLE> </EXPERIENCE> </EXPERIENCES> </CANDIDATE> </CANDIDATES>
Partager