Re: Parcourir un arbre
Eric van der Vlist <[email protected]> Fri, 11 Sep 2009 22:02:55 +0200
| Newsgroups | gmane.text.xml.french.tech |
|---|---|
| Organization | Dyomedea (http://dyomedea.com) |
| Message-ID | <[email protected]> |
Bonjour,
Le lundi 31 ao=FBt 2009 =E0 13:15 +0200, Gregory Bittan a =E9crit :
> Bonjour,
> J'ai les d=E9finitions des arcs d'un graph ultra simple. Chaque sommet =
a un
> seul arc.
>=20
> <arc from=3DA to=3DB">
> <arc from=3DC to=3DD">
> <arc from=3DB to=3DC">
>=20
> Je souhaiterais afficher : A - B - C -D
>=20
> Une id=E9e ?=20
Si vos graphes sont aussi simples et qu'ils ont un "d=E9but" et sont
lin=E9aires, la transformation suivante :
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xsl:stylesheet xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" versio=
n=3D"1.0">
<xsl:output indent=3D"yes"/>
<xsl:template match=3D"graphe">
<arcs>
<xsl:apply-templates select=3D"arc[not(@from =3D ../arc/@to)]=
"/>
</arcs>
</xsl:template>
<xsl:template match=3D"arc">
<arc>
<step>
<xsl:value-of select=3D"@from"/>
</step>
<xsl:apply-templates select=3D"." mode=3D"to"/>
</arc>
</xsl:template>
<xsl:template match=3D"arc" mode=3D"to">
<step>
<xsl:value-of select=3D"@to"/>
</step>
<xsl:apply-templates select=3D"../arc[@from =3D current()/@to]" m=
ode=3D"to"/>
</xsl:template>
</xsl:stylesheet>
appliqu=E9e =E0 :
<graphe>
<arc from=3D"A" to=3D"B"/>
<arc from=3D"C" to=3D"D"/>
<arc from=3D"B" to=3D"C"/>
</graphe>
donnera :
<arcs>
<arc>
<step>A</step>
<step>B</step>
<step>C</step>
<step>D</step>
</arc>
</arcs>
Cordialement,
Eric van der Vlist
> Merci beaucoup.
--=20
Eric van der Vlist <[email protected]>
Dyomedea (http://dyomedea.com)