Bonjour,

J'ai ce 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
18
19
20
21
22
23
24
25
<XMLCODE>
    <ex>
        <z>bla</z>
        <z>bla</z>
        <par type="rom"/>
        <k>bla</k>
        <b>bla</b>
        <par type="rom"/>
        <b>bla</b>
        <h>bla</h>
        <par type="num"/>
        <z>bla</z>
        <par type="par"/>
        <e>bla</e>
        <par type="rom"/>
        <j>bla</j>
        <par type="rom"/>
        <i>bla</i>
        <par type="num"/>
        <y>bla</y>
        <par type="num"/>
        <y>bla</y>
 
    </ex>
</XMLCODE>
Je dois
1° : Créer une hiérarchie rom>num>par
2° : isoler les éléments qui se trouvent entre 'rom' et 'num' mais pas ceux entre 'rom' et 'rom'. Dans mon exemple il me faut celui la :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
<par type="rom"/>
        <b>bla</b>
        <h>bla</h>
        <par type="num"/>
mais pas :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
<par type="rom"/>
        <j>bla</j>
        <par type="rom"/>

J'ai créé la hiérarchie grâce à une fonction mais j'ai "triché" pour le point 2.
J'aimerai tout intégrer à ma fonction. Est-ce possible, faut-il faire une autre fonction. Je sèche un peu. Je suis preneuse de conseils :-)
Merci
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
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mf="http://example.org/mf"
    exclude-result-prefixes="xs mf">
 
    <xsl:output method="xml" indent="yes"/>
 
 
    <xsl:template match="* | @* | text()">
        <xsl:copy>
            <xsl:apply-templates select="* | text() | @*"/>
        </xsl:copy>
    </xsl:template>
 
 
    <xsl:param name="max-level" as="xs:integer" select="3"/>
 
    <xsl:function name="mf:group" as="node()*">
        <xsl:param name="items" as="node()*"/>
        <xsl:param name="level" as="xs:integer"/>
 
        <xsl:variable name="name" select="('rom', 'num', 'par')[$level]"/>
 
 
        <xsl:for-each-group select="$items" group-starting-with="par[@type = $name]">
            <xsl:choose>
                <xsl:when test="self::par[@type = $name]">
                    <xsl:element name="SENSE">
                        <xsl:copy-of select="."/>
 
 
                        <xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
 
                    </xsl:element>
                </xsl:when>
                <xsl:when test="$level lt $max-level">
                    <xsl:sequence select="mf:group(current-group(), $level + 1)"/>
                </xsl:when>
 
                <xsl:otherwise>
                    <xsl:apply-templates select="current-group()"/>
                </xsl:otherwise>
 
            </xsl:choose>
        </xsl:for-each-group>
 
    </xsl:function>
 
    <xsl:template match="ex">
        <xsl:copy>
            <xsl:sequence select="mf:group(*, 1)"/>
        </xsl:copy>
    </xsl:template>
 
    <xsl:template match="*[preceding-sibling::*[self::par[@type='rom'] or self::par[@type='num']][1]/self::par[@type='rom'] ]">
        <xsl:choose>
            <xsl:when test=".[following-sibling::*[self::par[@type='rom'] or self::par[@type='num']][1]/self::par[@type='num']][not(self::par[@type='rom'])] [not( self::par[@type='num'])]">
                <span>
                    <xsl:copy-of select="."/>
                </span>
            </xsl:when>
            <xsl:otherwise>
                <xsl:copy-of select="."/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
 
 
</xsl:stylesheet>