🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: fr.comp.text.xml
4 messages
4 total messages Started by Rapha�l THERY Tue, 28 Nov 2000 00:00
Supprimer un doublon
#10198
Author: Rapha�l THERY
Date: Tue, 28 Nov 2000 00:00
50 lines
2038 bytes
Certes la question a d�j� �t� pos�e mais sans r�ponses ....

j'ai un flux xml
<root>
  <champ nom="toto" .... />
  <champ nom="titi" .... />
  <champ nom="tutu" .... />
  <champ nom="tutu" .... />
  <champ nom="tata" .... />
  <champ nom="toto" .... />
  <champ nom="tata" .... />
  <champ nom="titi" .... />
  <champ nom="titi" .... />
</root>

je voudrais supprimer les doublons pour n'avoir plus que ;
<root>
  <champ nom="toto" .... />
  <champ nom="titi" .... />
  <champ nom="tutu" .... />
  <champ nom="tata" .... />
</root>

pour cela j'applique une feuille de styles :
(l'objet : Parcourir la liste des �l�ments "champ" et cr�er un noeud s'il
n'existe pas d�j� dans le noeud r�sultat !)
<xsl:template match="root">
  <xsl:element name="Resultat" >
    <xsl:for-each select="*" >
      <xsl:sort select="@nom" order="ascending" />
      <xsl:variable name="monNom" select="@nom" />
      <xsl:if test="not($monNom=//Resultat/Champ[@nom])">
        <xsl:apply-templates select="." />
      </xsl:if>
    </xsl:for-each>
  </xsl:element>
</xsl:template>

<xsl:template match="Champ">
 <xsl:element name="Champ">
  <xsl:attribute name="nom">
  <xsl:value-of select="@nom" />
 </xsl:attribute>
 </xsl:element>
</xsl:template>

bien evidemment cela ne marche pas (je soup�onne le test if)

merci pour vos conseils
Rapha�l
Re: Supprimer un doublon
#10199
Author: Rapha�l THERY
Date: Tue, 28 Nov 2000 00:00
70 lines
2786 bytes
J'ai enfin trouv� .... si cela interesse !
Gr�ce au tri j'ai pu utiliser une variable !

<xsl:template match="root">
<xsl:element name="Resultat" >
  <xsl:variable name="maVariable" select="" />
  <xsl:for-each select="*" >
    <xsl:sort select="@nom" order="ascending" />
    <xsl:if test="$maVariable = @nom">
      <xsl:apply-templates select="." />
    </xsl:if>
 <xsl:variable name="maVariable" select="@nom" />
  </xsl:for-each>
</xsl:element></xsl:template>


Rapha�l THERY <raphael.thery@nordnet.fr> a �crit dans le message :
72MU5.66$Fc.280770@nnrp1.proxad.net...
> Certes la question a d�j� �t� pos�e mais sans r�ponses ....
>
> j'ai un flux xml
> <root>
>   <champ nom="toto" .... />
>   <champ nom="titi" .... />
>   <champ nom="tutu" .... />
>   <champ nom="tutu" .... />
>   <champ nom="tata" .... />
>   <champ nom="toto" .... />
>   <champ nom="tata" .... />
>   <champ nom="titi" .... />
>   <champ nom="titi" .... />
> </root>
>
> je voudrais supprimer les doublons pour n'avoir plus que ;
> <root>
>   <champ nom="toto" .... />
>   <champ nom="titi" .... />
>   <champ nom="tutu" .... />
>   <champ nom="tata" .... />
> </root>
>
> pour cela j'applique une feuille de styles :
> (l'objet : Parcourir la liste des �l�ments "champ" et cr�er un noeud s'il
> n'existe pas d�j� dans le noeud r�sultat !)
> <xsl:template match="root">
>   <xsl:element name="Resultat" >
>     <xsl:for-each select="*" >
>       <xsl:sort select="@nom" order="ascending" />
>       <xsl:variable name="monNom" select="@nom" />
>       <xsl:if test="not($monNom=//Resultat/Champ[@nom])">
>         <xsl:apply-templates select="." />
>       </xsl:if>
>     </xsl:for-each>
>   </xsl:element>
> </xsl:template>
>
> <xsl:template match="Champ">
>  <xsl:element name="Champ">
>   <xsl:attribute name="nom">
>   <xsl:value-of select="@nom" />
>  </xsl:attribute>
>  </xsl:element>
> </xsl:template>
>
> bien evidemment cela ne marche pas (je soup�onne le test if)
>
> merci pour vos conseils
> Rapha�l
>
>
Re: Supprimer un doublon
#10201
Author: Tom.
Date: Tue, 28 Nov 2000 00:00
38 lines
2244 bytes
In article <0kMU5.25$P8.119926@nnrp2.proxad.net>, "Rapha�l THERY"
<raphael.thery@nordnet.fr> wrote:
> <xsl:template match="root">
> <xsl:element name="Resultat" >
>   <xsl:variable name="maVariable" select="" />
>   <xsl:for-each select="*" >
>     <xsl:sort select="@nom" order="ascending" />
>     <xsl:if test="$maVariable = @nom">
>       <xsl:apply-templates select="." />
>     </xsl:if>
>  <xsl:variable name="maVariable" select="@nom" />
>   </xsl:for-each>
> </xsl:element></xsl:template>

Si ton processeur XSLT te l'autorise, il n'est pas conforme � la
Recommendation.
In http://www.w3.org/TR/xslt#local-variables :
  "It is an error if a binding established by an xsl:variable or
   xsl:param element within a template shadows another binding
   established by an xsl:variable or xsl:param element also within the
   template"
En d'autres termes : il n'y a pas d'affectation en XSLT. Comme
quelqu'un le soulignait sur c.t.x, XSLT est un langage fonctionnel, pas
proc�dural, donc pas d'affectation.

C'�tait bien un probl�me dans ton xsl:if :
>  <xsl:variable name="monNom" select="@nom" />
>  <xsl:if test="not($monNom=//Resultat/Champ[@nom])">
Tu compares la valeur de l'attribut @nom avec la valeur du premier
Champ qui poss�de un attribute @nom.

Ce qu'il te faut, c'est plutot savoir si un Champ pr�c�dent avait le
m�me @nom :
  <xsl:if test="not(preceding-sibling::Champ[@nom = current()/@nom])"
Est-ce qu'il existe un pr�c�dent Champ ayant le m�me @nom ? S'il n'y en
a pas on "ex�cute" le contenu du xsl:if

Tom.
Re: Supprimer un doublon
#10202
Author: Rapha�l THERY
Date: Tue, 28 Nov 2000 00:00
47 lines
2812 bytes
Tout � fait, j'ai fais mes tests avec Stylus qui lui accepte sans probl�me
ce que j'ai propos� ... (� merveille, je dirais )
ensuite je mets en production (pour cela j'utiliser xalan) et l� .... BIG
Probl�me !

par contre TA SOLUTION r�soud tous mes probl�mes je t'en remercie !

Tom. <ptittom@free.fr> a �crit dans le message :
ms9009.ah.ln@ptittom.free.fr...
> In article <0kMU5.25$P8.119926@nnrp2.proxad.net>, "Rapha�l THERY"
> <raphael.thery@nordnet.fr> wrote:
> > <xsl:template match="root">
> > <xsl:element name="Resultat" >
> >   <xsl:variable name="maVariable" select="" />
> >   <xsl:for-each select="*" >
> >     <xsl:sort select="@nom" order="ascending" />
> >     <xsl:if test="$maVariable = @nom">
> >       <xsl:apply-templates select="." />
> >     </xsl:if>
> >  <xsl:variable name="maVariable" select="@nom" />
> >   </xsl:for-each>
> > </xsl:element></xsl:template>
>
> Si ton processeur XSLT te l'autorise, il n'est pas conforme � la
> Recommendation.
> In http://www.w3.org/TR/xslt#local-variables :
>   "It is an error if a binding established by an xsl:variable or
>    xsl:param element within a template shadows another binding
>    established by an xsl:variable or xsl:param element also within the
>    template"
> En d'autres termes : il n'y a pas d'affectation en XSLT. Comme
> quelqu'un le soulignait sur c.t.x, XSLT est un langage fonctionnel, pas
> proc�dural, donc pas d'affectation.
>
> C'�tait bien un probl�me dans ton xsl:if :
> >  <xsl:variable name="monNom" select="@nom" />
> >  <xsl:if test="not($monNom=//Resultat/Champ[@nom])">
> Tu compares la valeur de l'attribut @nom avec la valeur du premier
> Champ qui poss�de un attribute @nom.
>
> Ce qu'il te faut, c'est plutot savoir si un Champ pr�c�dent avait le
> m�me @nom :
>   <xsl:if test="not(preceding-sibling::Champ[@nom = current()/@nom])"
> Est-ce qu'il existe un pr�c�dent Champ ayant le m�me @nom ? S'il n'y en
> a pas on "ex�cute" le contenu du xsl:if
>
> Tom.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads