Re: Aggregation sous XML
COUTHURES Alain <[email protected]> Thu, 27 Mar 2008 15:13:35 +0100
| Newsgroups | gmane.text.xml.french.tech |
|---|---|
| Message-ID | <[email protected]> |
Bonjour,
Voilà ce que je vous propose pourvu que votre document en entrée ne soit
pas trop volumineux :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Units>
<xsl:for-each
select="/Units/UnitType[not(preceding-sibling::UnitType=.)]">
<Unit>
<xsl:variable name="current" select="."/>
<xsl:copy-of select="."/>
<NumberOfUnits><xsl:value-of
select="count(parent::*/UnitType[.=$current])"/></NumberOfUnits>
</Unit>
</xsl:for-each>
</Units>
</xsl:template>
</xsl:stylesheet>
Bien cordialement,
Alain COUTHURES
<agenceXML>
http://www.agencexml.com
Aguero, Dimitri a écrit :
> Bonjour,
>
> Est-ce qu'il y aurait un moyen de convertir
>
> <Units>
> <UnitType>STB</UnitType>
> <UnitType>LNK-ROUTER-123</UnitType>
> <UnitType>DKTbox</UnitType>
> <UnitType>STB</UnitType>
> <UnitType>STB</UnitType>
> <UnitType>DKTbox</UnitType>
> </Units>
>
> Dans:
>
> <Units>
> <Unit>
> <UnitType>STB</UnitType>
> <NumberOfUnits>3</ NumberOfUnits >
> </Unit>
> <Unit>
> <UnitType> LNK-ROUTER-123</UnitType>
> <NumberOfUnits>1</ NumberOfUnits >
> </Unit>
> <Unit>
> <UnitType> DKTbox </UnitType>
> <NumberOfUnits>2</ NumberOfUnits >
> </Unit>
> </Units>
>
> Et ce, avec une seule transformation ?
> Merci d'avance de toute aide
>
> Cordialement
> Dimitri
>
> --
> Devenez redacteur <XML>fr et contribuez au developpement du
> xml francophone (http://xmlfr.org/infos/redacteurs/) !
>
> Liste de diffusion "[email protected]" (http://xmlfr.org).
>
> Cette liste est a votre disposition pour discuter en francais de
> tout sujet technique lie a XML.
>
> Pour resilier votre abonnement, envoyez un message contenant
> la commande "unsubscribe" a [email protected]
> (mailto:[email protected]?Subject=unsubscribe)
>
>
>