[XSLT] structures imbriquées
Bonjour,
J'ai un fichier XML présentant des structures récurrentes (une arborescence):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="ex-033_nested.xsl"?>
<items>
<item>
<item><id>1.1</id></item>
<item><id>1.2</id></item>
<item>
<item><id>1.2.1</id></item>
<item>
<item><id>1.2.1.1</id></item>
<item><id>1.2.1.2</id></item>
</item>
<item><id>1.2.2</id></item>
</item>
</item>
<item>
<item><id>2.1</id></item>
<item><id>2.2</id></item>
</item>
<item><id>3</id></item>
</items> |
J'ai ensuite le XSL suivant pour le présenter:
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
|
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="item">
<ul>
<li>
<xsl:value-of select="./item" />
<xsl:apply-templates />
</li>
</ul>
</xsl:template>
</xsl:stylesheet> |
Ça marche sauf qu'il y a répétition d'un item!
http://bonnal.home.cern.ch/bonnal/new-2.gif
J'ai donc localisé le problème potentiel:
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
|
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:with-param name="noeud" select="/" />
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="item">
<xsl:param name="noeud" />
<xsl:choose>
<xsl:when test="$noeud/*">
<xsl:apply-templates />
<xsl:with-param name="noeud" select="$noeud/*" />
</xsl:when>
<xsl:otherwise>
<ul>
<li>
<xsl:value-of select="./item" />
</li>
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet> |
Mais là ça ne marche plus du tout !!!
Une bonne volonté pour éclairer ma chandelle?
Merci,
P.