Utilisation de preceding-sibling
Bonjour,
Je rencontre un problème avec une transformation XSLT.
Je dispose d'un fichier xml de ce type :
Code:
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
|
<?xml version="1.0" encoding="iso-8859-1"?>
<html>
<body>
<table border="0" width="640" cellpadding="1" cellspacing="5">
<tr class="rt">
<td colspan="3">A0</td>
</tr>
<tr class="rt">
<td>B1</td>
<td>B2</td>
<td>B3</td>
</tr>
<tr class="rt">
<td>C1</td>
<td>C2</td>
<td>C3</td>
</tr>
<tr>
<td colspan="3">D0</td>
</tr>
<tr class="rt">
<td>E1</td>
<td>E2</td>
<td>E3</td>
</tr>
<tr class="rt">
<td colspan="3">F0</td>
</tr>
<tr class="rt">
<td>G1</td>
<td>G2</td>
<td>G3</td>
</tr>
<tr class="rt">
<td>H1</td>
<td>H2</td>
<td>H3</td>
</tr>
</table>
</body>
</html> |
Et je souhaiterais afficher un tableau html de la forme suivante :
Code:
1 2 3 4 5 6
|
A0 --- B1 --- B2 --- B3
A0 --- C1 --- C2 --- C3
D0 --- E1 --- E2 --- E3
F0 --- G1 --- G2 --- G3
F0 --- H1 --- H2 --- H3 |
Pour cela, j'ai donc utilisé preceding-sibling :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
<xsl:for-each select="//tr[@class='rt']">
<xsl:if test="string-length(td[position()=2]/.)>0">
<xsl:choose>
<xsl:when test="preceding-sibling::tr/td/@colspan='3'">
<xsl:value-of select="preceding-sibling::tr/td/."/>
</xsl:when>
</xsl:choose>
--- <xsl:value-of select="td[position()=1]/."/> --- <xsl:value-of select="td[position()=2]/."/> --- <xsl:value-of select="td[position()=3]/."/><br/>
</xsl:if>
</xsl:for-each> |
J'obtiens le résultat suivant :
Code:
1 2 3 4 5 6
|
A0 --- B1 --- B2 --- B3
A0 --- C1 --- C2 --- C3
A0 --- E1 --- E2 --- E3
A0 --- G1 --- G2 --- G3
A0 --- H1 --- H2 --- H3 |
Comment faire pour récupérer la bonne première valeur de chaque ligne : comment récupérer la valeur du tag tr[@colspan='3'] le plus proche (précédent) du tag tr en cours?
Merci d'avance pour votre aide