Bonjour à tous,

Je débute en XSLT et je cherche à regrouper des éléments grace à des attributs des enfants, ne maitrisent pas encore suffisamment le langage, je m'y perds,

voici mon xml de départ

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
<?xml version="1.0" encoding="UTF-8"?>
<blocs>
     <bloc>
          <prenon>Philippe</prenon>
          <date>2014-12-01</date>
          <category text="E1"/>
     </bloc>
     <bloc>
          <prenon>Pol</prenon>
          <date>2013-10-15</date>
          <category text="D1">
               <category text="D3B"/>
          </category>
     </bloc>
     <bloc>
          <prenon>Jacque</prenon>
          <date>2013-08-08</date>
          <category text="D1">
               <category text="D2B"/>
          </category>
     </bloc>
     <bloc>
          <prenon>Jean</prenon>
          <date>2015-10-26</date>
          <category text="D1">
               <category text="D2A"/>
          </category>
     </bloc>
     <bloc>
          <prenon>Claude</prenon>
          <date>2017-10-03</date>
          <category text="D1">
               <category text="D2C"/>
          </category>
     </bloc>
     <bloc>
          <prenon>Ema</prenon>
          <date>2013-06-05</date>
          <category text="D1">
               <category text="D2A"/>
          </category>
     </bloc>
</blocs>
et voici le résulta que je recherche :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>
<root>
      <d1>Niveau1d</d1>
          <d2a>Niveau2da</d2a>
               <prenon>Jean</prenon>
               <prenon>Ema</prenon>
          <d2b>Niveau2db</d2b>
               <prenon>Pierre</prenon>
               <prenon>Jacque</prenon>
          <d2c>Niveau2dc</d2c>
               <prenon>Claude</prenon>
      <e1>Niveau1e</e1>
          <prenon>Philippe</prenon>
</root>
Voici une des versions que j'ai peu faire :
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY folder "file://links/">
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
 
     <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
 
     <xsl:variable name="livresAuCatalogue" select="/blocs/bloc"/>
 
     <xsl:template match="bloc">
          <xsl:variable name="blocCourante" select="."/>
          <xsl:for-each select="$livresAuCatalogue">
        <!--       <xsl:sort select="$blocCourante/date" order="descending"/>-->
              <xsl:choose>
                   <xsl:when test="$blocCourante/category/@text = 'D1' ">
                   - <xsl:value-of select="$blocCourante/prenon"/><xsl:text></xsl:text><xsl:value-of select="$blocCourante/category/@text"/>
                   </xsl:when>
                   <xsl:when test="$blocCourante/category/@text = 'E1' ">
                        - <xsl:value-of select="$blocCourante/prenon"/><xsl:text></xsl:text><xsl:value-of select="$blocCourante/category/@text"/>
                   </xsl:when>
              </xsl:choose>
           </xsl:for-each>
     </xsl:template>
</xsl:stylesheet>
Je pence que mon problème est d'être perdu dans l'arbre.

Merci à vous