Bonjour,
je rencontre actuellement un soucis dans la transformation d'attributs en éléments. En effet je désire convertir tous les attributs de mon document XML en éléments.
Etant débutant en technologie XSL/XSLT je me suis tourné vers google et j'ai trouvé ce bout de code:
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
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   version="1.0">
  <xsl:output indent="yes" />
  <xsl:strip-space elements="*" />
  <xsl:template match="*">
    <xsl:copy>
      <xsl:if test="@*">
        <xsl:for-each select="@*">
          <xsl:element name="{name()}">
            <xsl:value-of select="." />
          </xsl:element>
        </xsl:for-each>
      </xsl:if>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
Malheureusement, il ne me convient pas à 100% et je n'arrive pas à le modifier de manière à obtenir le résultat tant attendu.
En effet, ce code fonctionne trop bien car il transforme même les attributs particuliers (xsi:*, xmlns:*) en élément ce qui est assez gênant.

Voici un extrait du document XML à transformer:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<parameters xsi:noNamespaceSchemaLocation="parametres.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <client id="XXX" name="HOTEL-Blablablabla" street="Rue de blablabla" zip="XXXXX" city="VILLE" phone="123456789" email="x@y.ch" canton="YX">
      <product id="500" idinternal="200,201,213,236">
         <subposition id="101" type="0">
            <employeepart type="false" man="5.05" woman="5.05"/>
            <employerpart man="5.05" woman="5.05" additionalcost="3.45" administrationcost="3"/>
         </subposition>
...
Résultat avec le bout de code ci-dessus:
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
<?xml version = '1.0'?>
<parameters>
   <xsi:noNamespaceSchemaLocation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">parametres.xsd</xsi:noNamespaceSchemaLocation>
   <xmlns:xsi xmlns:xmlns="http://www.w3.org/2000/xmlns/">http://www.w3.org/2001/XMLSchema-instance</xmlns:xsi>
   <client>
      <id>XXX</id>
      <name>HOTEL-Blablablabla</name>
      <street>Rue de blablabla</street>
      <zip>XXXXX</zip>
      <city>VILLE</city>
      <phone>123456789</phone>
      <email>x@y.ch</email>
      <canton>YX</canton>
      <product>
         <id>500</id>
         <idinternal>200,201,213,236</idinternal>
         <subposition>
            <id>101</id>
            <type>0</type>
            <employeepart>
               <type>false</type>
               <man>5.05</man>
               <woman>5.05</woman>
            </employeepart>
            <employerpart>
               <man>5.05</man>
               <woman>5.05</woman>
               <additionalcost>3.45</additionalcost>
               <administrationcost>3</administrationcost>
            </employerpart>
         </subposition>
...
Résultat attendu:
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
<?xml version = '1.0'  encoding = 'ISO-8859-1'?>
<parameters xsi:noNamespaceSchemaLocation="parametres.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <client>
      <id>XXX</id>
      <name>HOTEL-Blablablabla</name>
      <street>Rue de blablabla</street>
      <zip>XXXXX</zip>
      <city>VILLE</city>
      <phone>123456789</phone>
      <email>x@y.ch</email>
      <canton>XY</canton>
      <product>
         <id>500</id>
         <idinternal>200,201,213,236</idinternal>
         <subposition>
            <id>101</id>
            <type>0</type>
            <employeepart>
               <type>false</type>
               <man>5.05</man>
               <woman>5.05</woman>
            </employeepart>
            <employerpart>
               <man>5.05</man>
               <woman>5.05</woman>
               <additionalcost>3.45</additionalcost>
               <administrationcost>3</administrationcost>
            </employerpart>
         </subposition>
La question: Comment transformer l'arborescence de "parameters" en éléments sans modifier les attributs particulier de parameters?

Merci de votre attention.
Je vous souhaite un excellent après-midi.