Bonjour,
j'ai le fichier XML ci dessous:
Un fichier xsl lui est associé afin de mettre en forme le contenu du fichier xml, j'aimerais depuis ce fichier pouvoir a l'aide de fonction javascript présente dans le xsl modifier le contenu du fichier 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 <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="fichier_TEST.xsl"?> <Liste_des_Produits xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="fichier_schema.xsd"> <Produit> <Nom_Produit>Boulon inox 5x12</Nom_Produit> <Reference>LM889</Reference> <Categorie>visserie</Categorie> <Niveau_Danger>inerte</Niveau_Danger> <Stockage> <Emplacement>L1C1</Emplacement> <Nombre_de_Palette>3</Nombre_de_Palette> <Quantite>3500</Quantite> </Stockage> <Stockage> <Emplacement>L1C5</Emplacement> <Nombre_de_Palette>4</Nombre_de_Palette> <Quantite>2500</Quantite> </Stockage> </Produit> </Liste_des_Produits>
Par exemepl, je souhaite modifier la référence "LM889" en "AA000", pour cela j'ai réalisé cette fonction cependant ceci ,e fonctionne pas et ne connaissant que trés peu de chose sur javascript je ne comprend pas vraiment l'erreur alors si vous pouviez m'aider cela me rendrai grand service.
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="id" match="Categorie" use="."/> <xsl:template match="/"> <html> <head> <title>Liste produit disponible</title> <script language="JavaScript"> <![CDATA[function Insertion() { //code pour IE if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("D:\Documents and Settings\cDucarouge\Mes documents\Etude technique Extranet\ETL\Web Service\Proto Dom_JS\fichier_xml2.xml"); XmlNodeList elemList = xmlDocument .GetElementsByTagName("Reference"); for (int i=0; i < elemList.Count; i++) { elemList[i].GetElementsByTag("AA000") = "BB089"; } alert('Ici, c\'est vIE!\nSympa non ?'); } //Code pour FireFox else if (document.implementation && document.implementation.createDocument) { xmlDoc= document.implementation.createDocument("","",null); xmlDoc.load("D:\Documents and Settings\cDucarouge\Mes documents\Etude technique Extranet\ETL\Web Service\Proto Dom_JS\fichier_xml2.xml"); alert('Ici, c\'est votre message!\nSympa non ?'); } else { alert('Votre browser en vous permet pas l\'utilisation de cet outil'); } } ]]> </script> </head> <body> <h1> Question 2 </h1> <xsl:apply-templates select="//Liste_des_Produits"/> </body> </html> </xsl:template> <xsl:template match="//Liste_des_Produits"> <xsl:param name="choix"> 1 </xsl:param> <xsl:choose> <xsl:when test="$choix=1"> <table> <caption> Liste produit - 2 </caption> <tr><th>Nom Produit</th> <th> Référence</th> <th> Catégorie </th></tr> <xsl:for-each select="/Liste_des_Produits/Produit"> <xsl:sort select="Nom_Produit"/> <tr> <td class="nom"> <xsl:value-of select = "Nom_Produit"/> </td> <td class="niv"><xsl:value-of select ="Reference"/></td> <td class="emp"><xsl:value-of select ="Categorie"/> </td> </tr> </xsl:for-each> </table> <form method="post"> <TR> <TD> <INPUT type="submit" value="Ajouter" onclick="Insertion()"/> </TD> </TR> </form> </xsl:when> <xsl:otherwise> <table> <caption> Liste produit - 1 </caption> <tr><th>Nom Produit</th> <th> Niveau danger</th> <th> Emplacement </th></tr> <xsl:for-each select="/Liste_des_Produits/Produit"> <xsl:sort select="Niveau_Danger"/> <tr> <td class="nom"> <xsl:value-of select = "Nom_Produit"/> </td> <td class="niv"><xsl:value-of select ="Niveau_Danger"/></td> <td class="emp"><xsl:value-of select ="Stockage/Emplacement"/> </td> </tr> </xsl:for-each> </table> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Partager