Bonsoir à tous,
J'ai un fichier XML contenant une très grosse quantité de données que je veux convertir en CSV, (Format nécéssaire pour le logiciel qui reçoit ces données).
J'ai donc fait un XSL qui transforme le fichier en CSV mais j'ai un petit souci d'arborescence, je m'explique :
Voici un extrait de mon fichier XML :
Comme vous l'aurez remarqué, il y a 2 types de variables, une ayant une Alarme <Alarm name="S7-400 d_faut Rack 1 Carte 1"> , et l'autre non.
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 <Tags> <Tag name="SYS_ACQ_DEPOUB" path="" type="OPC"> <Property name="Datatype">6</Property> <Property name="Value">1</Property> <Property name="OPCServer">S7 TCP-IP</Property> <Property name="OPCItemPath">[DEPOUSSIERAGE]DB50,X21.2</Property> <Property name="Scalemode">0</Property> <Property name="RawLow">0.000000</Property> <Property name="RawHigh">1.000000</Property> <Property name="ScaledLow">0.000000</Property> <Property name="ScaledHigh">1.000000</Property> <Property name="FormatString"></Property> <Property name="EngUnit"></Property> <Property name="HistoryEnabled">0</Property> <Property name="PrimaryHistoryProvider">CIFC</Property> </Tag> <Tag name="SYS_AL_S_01_01" path="" type="OPC"> <Property name="Datatype">6</Property> <Property name="Value">1</Property> <Property name="OPCServer">S7 TCP-IP</Property> <Property name="OPCItemPath">[414]DB10,X80.1</Property> <Property name="Scalemode">0</Property> <Property name="RawLow">0.000000</Property> <Property name="RawHigh">1.000000</Property> <Property name="ScaledLow">0.000000</Property> <Property name="ScaledHigh">1.000000</Property> <Property name="FormatString"></Property> <Property name="EngUnit"></Property> <Property name="HistoryEnabled">0</Property> <Property name="PrimaryHistoryProvider">CIFC</Property> <Alarms> <Alarm name="S7-400 d_faut Rack 1 Carte 1"> <Property name="priority">1</Property> <Property name="setpointA">1.000000</Property> <Property name="displayPath">HISTO_CIFC</Property> </Alarm> </Alarms> </Tag> </Tags>
Si il n'y a pas d'alarme, les variables correspondantes doivent être mise à "0", sinon on renseigne 4 colonnes avec "Alarme Name" et les 3 valeurs des property.
Mon Fichier Xsl se présente comme suit :
Ne maitrisant pas du tout le Xsl je suis complètement perdu, je souhaite obtenir un .CSV de la sorte :
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 <?xml version="1.0"?> <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="/Tags" > <xsl:for-each select="Tag"> <xsl:text>;</xsl:text> <xsl:value-of select="parent::Tag/@name"/> <xsl:for-each select="Property"> <xsl:value-of select="Property"/> <xsl:text>;</xsl:text> </xsl:for-each> <xsl:text>; </xsl:text> </xsl:for-each> </xsl:template> </xsl:stylesheet>
En image :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 TAG name;Value;DataType;OPCServer;OPCItemPath;ScaleMode;RawLow;RawHigh;ScaledLow;ScaledHigh;FormatString;EngUnit;HistoryEnabled;Alarm name;priority;setpointA;displayPath;PrimaryHistoryProvider SYS_ACQ_DEPOUB;1;6;S7 TCP-IP;[DEPOUSSIERAGE]DB50,X21.2;0;0.000000;1.000000;0.000000;1.000000;;;0;;-1;0.000000;HISTO_CIFC;CIFC SYS_AL_S_01_01;1;6;S7 TCP-IP;[414]DB10,X80.1;0;0.000000;1.000000;0.000000;1.000000;;;0;S7-400 d_faut Rack 1 Carte 1;1;1.000000;HISTO_CIFC;CIFC
J'essaye de tester au fur et à mesure mais le fait qu'il y ait une condition me bloque completement..
J'imagine que ça doit pourtant être très simple? SI quelqu'un aurait une idée?
Merci d'avance!
Bonne soirée.
Partager