Bonjour,
J'ai un fichier XML de départ que je désire transformer en un autre fichier XML.
Au départ, je n'ai pas de namespace et je désire ajouter un namespace.
Voici mon fichier XML de départComme vous le voyez, la racine est simplement <Document>
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 <?xml version="1.0" encoding="UTF-8"?> <Document> <PmtInf> <ReqdColltnDt>2018-03-18</ReqdColltnDt> <DrctDbtTxInf> <PmtId> <EndToEndId>voice0116</EndToEndId> </PmtId> <!-- Attention cet element a un Attribut ! ! --> <InstdAmt Ccy="EUR">1242.19</InstdAmt> </DrctDbtTxInf> </PmtInf> <PmtInf> <ReqdColltnDt>2018-03-19</ReqdColltnDt> <DrctDbtTxInf> <PmtId> <EndToEndId>voice0349</EndToEndId> </PmtId> <InstdAmt Ccy="EUR">1055.12</InstdAmt> </DrctDbtTxInf> <DrctDbtTxInf> <PmtId> <EndToEndId>voice0143</EndToEndId> </PmtId> <InstdAmt Ccy="EUR">750.32</InstdAmt> </DrctDbtTxInf> </PmtInf> </Document>
Je désire obtenir une racine comme ceci <Document xmlns="urn:iso:std:iso:202:tech">
Pour y parvenir, j'applique la transformation xslt suivanteCela fonctionne plutôt bien si ce n'est que je perds l'attribut Ccy
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 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- <xsl:strip-space elements="*"/> --> <xsl:output method="xml" indent="yes" encoding="utf-8"/> <xsl:template match="*[ancestor::Document]"> <xsl:element name="{local-name()}" namespace="urn:iso:std:iso:202:tech"> <xsl:apply-templates select="*|text()"/> </xsl:element> </xsl:template> <xsl:template match="Document|@*"> <Document xmlns="urn:iso:std:iso:202:tech"> <xsl:apply-templates select="*|text()"/> </Document> </xsl:template> </xsl:stylesheet>
Voici le résultat que j'obtiens :Mes noeuds InstdAmt ont perdu leur attribut !!
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 <?xml version="1.0" encoding="utf-8"?> <Document xmlns="urn:iso:std:iso:202:tech"> <PmtInf> <ReqdColltnDt>2018-03-18</ReqdColltnDt> <DrctDbtTxInf> <PmtId> <EndToEndId>voice0116</EndToEndId> </PmtId> <InstdAmt>1242.19</InstdAmt> </DrctDbtTxInf> </PmtInf> <PmtInf> <ReqdColltnDt>2018-03-19</ReqdColltnDt> <DrctDbtTxInf> <PmtId> <EndToEndId>voice0349</EndToEndId> </PmtId> <InstdAmt>1055.12</InstdAmt> </DrctDbtTxInf> <DrctDbtTxInf> <PmtId> <EndToEndId>voice0143</EndToEndId> </PmtId> <InstdAmt>750.32</InstdAmt> </DrctDbtTxInf> </PmtInf> </Document>
Là où j'ai <InstdAmt>1242.19</InstdAmt> ,
j'aurais dû garder<InstdAmt Ccy="EUR">1242.19</InstdAmt>
Comment puis-je faire pour garder l'attribut Ccy ?
Merci pour vos explications
Partager