Article View: fr.comp.text.xml
Article #413Re: [XSLT] regrouper plusieurs balises
From: Cbc
Date: Mon, 16 Jul 2007 21:22
Date: Mon, 16 Jul 2007 21:22
82 lines
3245 bytes
3245 bytes
Philippe Poulard a �crit :
> bon, je me lance ; si la liste des �l�ments ne fait pas 3km de long,
> c'est jouable malgr� les aller-retours...
>
> [...]
>
> voil� : pas test�, en direct, et sans filet
> j'esp�re ne pas m'�craser trop violemment :)
Bonjour,
merci beaucoup pour cette r�ponse. J'ai test� et... �a marche ! Le
document XML :
<?xml version="1.0" encoding="utf-8"?>
<doc>
<a>aa</a>
<b>bb</b>
<tag>t1</tag>
<tag>t2</tag>
<tag>t3</tag>
<c>cc</c>
<tag>t4</tag>
<tag>t5</tag>
<d>dd</d>
<e>ee</e>
</doc>
se transforme bien via :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--on est sur le premier tag d'une liste-->
<xsl:template
match="tag[not(preceding-sibling::*[1]=preceding-sibling::tag[1])]">
<tags>
<!--on s�lectionne le premier tag, et les suivants qui
n'ont pas de pr�c�dent non-"tag" qui soit apr�s le
premier (vous suivez ?)-->
<xsl:apply-templates select="self::tag |
following-sibling::tag[not(preceding-sibling::*[not(self::tag)][.=current()/following-sibling::*[not(self::tag)]])]"
mode="display"/>
</tags>
</xsl:template>
<!--on est sur les tags d'une liste, mais pas le premier-->
<xsl:template match="tag"/>
<!--pour copier les tags-->
<xsl:template match="tag" mode="display">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="doc">
<doc>
<xsl:apply-templates/>
</doc>
</xsl:template>
<xsl:template match="a|b|c|d|e">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
en :
<?xml version="1.0" encoding="utf-8"?>
<doc>
<a>aa</a>
<b>bb</b>
<tags>
<tag>t1</tag>
<tag>t2</tag>
<tag>t3</tag>
</tags>
<c>cc</c>
<tags>
<tag>t4</tag>
<tag>t5</tag>
</tags>
<d>dd</d>
<e>ee</e>
</doc>
Bravo, donc. :)
Technical Details
Message-ID:
<469be1b1$0$5108$ba4acef3@news.orange.fr>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!exabot.com!freenix!news.wanadoo.fr!news.wanadoo.fr!not-for-mailReferences:
<4698f085$0$5092$ba4acef3@news.orange.fr> <f7g335$4n4$1@news-sop.inria.fr>Show Full Headers
Complete Article Headers
X-Google-Thread: 114f60,a24909d6001453e7 X-Google-Attributes: gid114f60,public,usenet X-Google-Language: FRENCH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!exabot.com!freenix!news.wanadoo.fr!news.wanadoo.fr!not-for-mail Date: Mon, 16 Jul 2007 23:22:51 +0200 From: Cbc <cbc@yahooNS.fr> User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 Newsgroups: fr.comp.text.xml Subject: Re: [XSLT] regrouper plusieurs balises References: <4698f085$0$5092$ba4acef3@news.orange.fr> <f7g335$4n4$1@news-sop.inria.fr> In-Reply-To: <f7g335$4n4$1@news-sop.inria.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 000757-2, 16/07/2007), Outbound message X-Antivirus-Status: Clean Lines: 82 Message-ID: <469be1b1$0$5108$ba4acef3@news.orange.fr> Organization: les newsgroups par Orange NNTP-Posting-Date: 16 Jul 2007 23:22:57 CEST NNTP-Posting-Host: 90.2.200.92 X-Trace: 1184620977 news.orange.fr 5108 90.2.200.92:3892 X-Complaints-To: abuse@orange.fr