Bonjour, je cherche à créer un attribut id pour chaque noeud à partir du xsl, ce id commençant à 2 et s'incrémentant au fil des noeuds de l'arborescence.
Le format de l'attribut id="Id_x" du xml output est imposé.
Merci et à bientôt
Bernols
Le fichier à transformer : SAPinput.xml
SAP.xsl
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 <?xml version="1.0" encoding="UTF-16"?> <SAP xsi:noNamespaceSchemaLocation="SAP.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ficheInformation> <fiche> <NomDuDocument>sap</NomDuDocument> <TypeDuDocument>Fichier de données</TypeDuDocument> <DateDeCreation>2006-01-30</DateDeCreation> </fiche> <fiche> <NomDuDocument>sop</NomDuDocument> <TypeDuDocument>Fichier de texte</TypeDuDocument> <DateDeCreation>2006-01-30</DateDeCreation> </fiche> </ficheInformation> </SAP>
XML à obtenir : SAPoutputModele.xml
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 <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"> <!--modification de encoding--> <xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/> <xsl:template match="/SAP"> <ModeleExport> <xsl:apply-templates select="ficheInformation"/> </ModeleExport> </xsl:template> <!--conception de l'élément ficheInformation--> <xsl:template match="ficheInformation"> <ficheInformation id="{concat('Id_',position()+1)}"> <xsl:for-each select="fiche"> <fiche id="{concat('Id_',position()+'@id')}"> <NomDuDocument> <xsl:value-of select="NomDuDocument"/> </NomDuDocument> <TypeDuDocument>ModeleExport</TypeDuDocument> <DateDeCreation> <xsl:value-of select="DateDeCreation"/> </DateDeCreation> <InformationUsager> <xsl:value-of select="InformationUsager"/> </InformationUsager> </fiche> </xsl:for-each> </ficheInformation> </xsl:template> </xsl:stylesheet>
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 <?xml version="1.0" encoding="ISO-8859-1"?> <ModeleExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ficheInformation id="Id_2"> <fiche id="Id_3"> <NomDuDocument>sap</NomDuDocument> <TypeDuDocument>ModeleExport</TypeDuDocument> <DateDeCreation>2006-01-30</DateDeCreation> <InformationUsager></InformationUsager> </fiche> <fiche id="Id_4"> <NomDuDocument>sop</NomDuDocument> <TypeDuDocument>ModeleExport</TypeDuDocument> <DateDeCreation>2006-01-30</DateDeCreation> <InformationUsager></InformationUsager> </fiche> </ficheInformation> </ModeleExport>
Partager