Bonjour,
On me procure un document XML où toutes les balises contiennent un Cariage Return (caractère ASCII 13 ou la touche Enter de votre clavier) avant et après les données.
Comment puis-je supprimer tous ces Cariage Returns ?
Voici un exemple de fichier (simplifié) :et je voudrais le transformer pour obtenir ceci :
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 <Racine> <header> <DateProduced> 15/04/14 </DateProduced> </header> <trader_record> <city> NEW YORK </city> <Transaction> <WS> 3631L </WS> <EntryDate> 090414 </EntryDate> </Transaction> <Transaction> <WS> 8881L </WS> <EntryDate> 190314 </EntryDate> </Transaction> </trader_record> </Racine>une solution possible serait ceci :
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 <Racine> <header> <DateProduced>15/04/14</DateProduced> </header> <trader_record> <city>NEW YORK</city> <Transaction> <WS>3631L</WS> <EntryDate>090414</EntryDate> </Transaction> <Transaction> <WS>8881L</WS> <EntryDate>190314</EntryDate> </Transaction> </trader_record> </Racine>Mais cette solution m'oblige de programmer un template pour chaque balise une par une et il y en a beaucoup !
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 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="node()" /> </xsl:copy> </xsl:template> <xsl:template match="//DateProduced" > <xsl:variable name="Champ" select="current()"/> <xsl:element name="DateProduced"> <xsl:value-of select="fn:normalize-space($Champ)"/> </xsl:element> </xsl:template> <xsl:template match="//city" > <xsl:variable name="Champ" select="current()"/> <xsl:element name="city"> <xsl:value-of select="fn:normalize-space($Champ)"/> </xsl:element> </xsl:template> <xsl:template match="//WS" > <xsl:variable name="Champ" select="current()"/> <xsl:element name="WS"> <xsl:value-of select="fn:normalize-space($Champ)"/> </xsl:element> </xsl:template> </xsl:stylesheet>
N'y a-t-il pas moyen de de faire tout en un seul template ?
Merci pour vos suggestions.
Partager