Oui, j'ai mis la formule incorrecte par un numbre 1. Ce ligne#11
<xsl:for-each select="following-sibling::*[position() > 0 and position() < ($c - $p + 1)]">
doit se lire comme:
<xsl:for-each select="following-sibling::*[position() > 0 and position() < ($c - $p)]">
Mais pour arriver l'arithemetic correcte, il y a une correction sur la formula de p quand il n'y a plus following-sibling::SE_T (quelle confusion, pardon!) Au lieu de ça
<xsl:variable name="p" select="count(following-sibling::SE_T[1]/following-sibling::*)" />
je dois l'écrire comme ça:
1 2 3 4 5 6 7 8
| <xsl:variable name="p">
<xsl:if test="following-sibling::SE_T">
<xsl:value-of select="count(following-sibling::SE_T[1]/following-sibling::*)" />
</xsl:if>
<xsl:if test="not(following-sibling::SE_T)">
<xsl:value-of select="-1" />
</xsl:if>
</xsl:variable> |
Voilà la version entière révisée d'après cela pour éviter tout malentendu.
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
| <xsl:template match="CH">
<xsl:copy>
<xsl:apply-templates select="SE_T" />
</xsl:copy>
</xsl:template>
<xsl:template match="SE_T">
<SE>
<T><xsl:copy-of select="*|text()" /></T>
<xsl:variable name="c" select="count(following-sibling::*)" />
<xsl:variable name="p">
<xsl:if test="following-sibling::SE_T">
<xsl:value-of select="count(following-sibling::SE_T[1]/following-sibling::*)" />
</xsl:if>
<xsl:if test="not(following-sibling::SE_T)">
<xsl:value-of select="-1" />
</xsl:if>
</xsl:variable>
<xsl:for-each select="following-sibling::*[position() > 0 and position() < ($c - $p)]">
<xsl:choose>
<xsl:when test="name()='P'">
<xsl:copy-of select="." />
</xsl:when>
<xsl:otherwise>
<xsl:if test="name()!=name(preceding-sibling::*[1])">
<xsl:copy>
<xsl:call-template name="consolidate">
<xsl:with-param name="ctx" select="." />
<xsl:with-param name="name" select="name()" />
</xsl:call-template>
</xsl:copy>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</SE>
</xsl:template>
<xsl:template name="consolidate">
<xsl:param name="ctx" />
<xsl:param name="name" />
<xsl:if test="name($ctx)=$name">
<P><xsl:copy-of select="*|text()" /></P>
<xsl:call-template name="consolidate">
<xsl:with-param name="ctx" select="$ctx/following-sibling::*[1]" />
<xsl:with-param name="name" select="$name" />
</xsl:call-template>
</xsl:if>
</xsl:template> |
ps: Je dois mettre au point cette correction en deux temps pour arriver ça et j'espère je peux la mettre une pointe finale.
Partager