Bonjour,
Je débute dans ce domaine qui semble passionnant !
Je vous expose mon problème :
Je souhaite reformater un fichier XML. Je passe donc par XSL.
Mon fichier XML d'origine :
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
 
<Produits>
  <FicheProduit>
    <Famille>AA</Famille>
    <Article>AAAA</Article>
    <Libelle>AAAAAA</Libelle>
  </FicheProduit>
  <FicheProduit>
    <Famille>BB</Famille>
    <Article>BBBB</Article>
    <Libelle>BBBBBB</Libelle>
  </FicheProduit>
  <FicheProduit>
    <Famille>AA</Famille>
    <Article>CCCC</Article>
    <Libelle>CCCCCC</Libelle>
  </FicheProduit>
</Produits>
Par une transformation XSL, je souhaite obtenir un 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
 
<Produits>
  <Famille CodFam="AA">
    <Article>
      <Produit>AAAA</Article>
      <Libelle>AAAAAA</Libelle>
    </Article>
    <Article>
      <Produit>CCCC</Article>
      <Libelle>CCCCCC</Libelle>
    </Article>
  </Famille>
  <Famille CodFam="BB">
    <Article>
      <Produit>BBBB</Article>
      <Libelle>BBBBBB</Libelle>
    </Article>
  </Famille>
</Produits>
Voici mon XSL :
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
 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name="Produits">
  <xsl:for-each-group select="Produits/FicheProduit" group-by="Famille">
  <xsl:element name="Famille"><xsl:attribute name="CodFam"><xsl:value-of select="Famille"/></xsl:attribute>
    <xsl:for-each select=".">
    <xsl:element name="Article">
    <xsl:element name="Produit"><xsl:value-of select="Article"/></xsl:element>
    <xsl:element name="Libelle"><xsl:value-of select="Libelle"/></xsl:element>
    </xsl:element>
    </xsl:for-each>
  </xsl:element>
  </xsl:for-each-group>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
En gros, je souhaite regrouper les articles par famille.

Merci de votre aide.