Bonjour a tous,
je cherche à générer via XSL un fichier XML afin d'ajouter données. Pour l'instant je cherche à remplacer les valeurs de certains attributs d'un noeud.
Mon fichier source est le suivant
et mon fichier XSL
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <modules> <module fileurl="myFileUrl" filepath="myFilepath" /> </modules>
mon problème est que le code <xsl:when test="fileurl=project.iml"> n'est jamais appelé. Pourriez vous m'aider à comprendre où est mon erreur? merci d'avance
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 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output encoding="UTF-8" method="xml" indent="yes"/> <!-- Define global variables used inside this transformation (Note: The values are defined from the outside) --> <xsl:param name="companyName"/> <xsl:param name="productName"/> <xsl:template match="module"> <!-- <xsl:apply-templates/> --> <xsl:copy> <xsl:for-each select="attribute::node()"> <xsl:choose> <xsl:when test="fileurl=project.iml"> </xsl:when> <!--<xsl:when test="filepath"> fileurl="testFilePath" </xsl:when>--> <xsl:otherwise> <!-- <xsl:copy-of select="."/> --> </xsl:otherwise> </xsl:choose> </xsl:for-each> <!-- end loop --> </xsl:copy> <!-- --> </xsl:template> <xsl:template name="Replace"> <!--remplace une chaine par une autre--> <xsl:param name="chaine"/> <xsl:param name="chaineCherche"/> <xsl:param name="chaineRempl"/> <xsl:param name="Occur"/> <!--si Occur n'est pas rempli il remplace toutes les occurences--> <xsl:choose> <xsl:when test="contains($chaine,$chaineCherche) "> <xsl:choose> <xsl:when test="number($Occur)=0"> <xsl:value-of select="$chaine"/> </xsl:when> <xsl:when test="$Occur>0"> </xsl:when> <xsl:otherwise> <xsl:call-template name="Replace"> <xsl:with-param name="chaine" select="concat(substring-before($chaine,$chaineCherche),$chaineRempl,substring-after($chaine,$chaineCherche))"/> <xsl:with-param name="chaineCherche" select="$chaineCherche"/> <xsl:with-param name="chaineRempl" select="$chaineRempl"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="$chaine"/> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- Matches the root node and adds disclaimer to the top of the page. <xsl:template match="/"> <xsl:comment> <xsl:value-of select="$companyName"/> - <xsl:value-of select="$productName"/> :: Auto-generated file, DO NOT MODIFY! </xsl:comment> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> --> <!-- Copy all existing comments. This is needed as "*" does not match comment nodes. --> <xsl:template match="comment()"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- Copy any node that was not processed so far without a change -> This template simply copies source to destination without a change. This template guarantees that all nodes are seen and processed by the XSL process. --> <xsl:template match="*"> <xsl:copy> <xsl:for-each select="attribute::node()"> <xsl:copy-of select="."/> </xsl:for-each> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Partager