xsl-list
[Top] [All Lists]

RE: [xsl] XSL Processing to avoid repetitions

2010-06-16 09:10:54
Hi Martin.
Thanks for your answer, but it doesn't work for me.
I have resent a message with my real data.
Maybe your solution would work if I don't change it to fit my data :)
Thanks, anyway.
Regards,
Fabien



-----Message d'origine-----
De : Martin Honnen [mailto:Martin(_dot_)Honnen(_at_)gmx(_dot_)de] 
Envoyé : mercredi 16 juin 2010 15:23
À : xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Objet : Re: [xsl] XSL Processing to avoid repetitions

Fabien Tillier wrote:
Hi List.
I was wondering if anyone could help me to filter out data in an XML stream.
(can be xslt 2.0...)

For example, I have
<xml>
      <city>
            <name>Paris</name>
            <person>Paul</person>
      </city>
      <city>
            <name>New-York</name>
            <person>John</person>
      </city>
      <city>
            <name>Paris</name>
            <person>George</person>
      </city>
</xml>

I would like to have an XSL template able to output something like (using 
<OL> for example) Paris
      Paul
      George
New-York
      John

Actually, all I am able to do is to get
Paris
      Paul
New-York
      John
Paris
      George

With XSLT 2.0 you can use xsl:for-each-group to group the data
<ol>
   <xsl:for-each-group select="/xml/city" group-by="name">
     <li>
       <xsl:value-of select="current-grouping-key()"/>
       <ol>
         <xsl:for-each select="current-group()/person">
           <li><xsl:value-of select="."/></li>
         </xsl:for-each>
       </ol>
     </li>
   </xsl:for-each-group>
</ol>


(please note that the real structure is more complicated, and the filter is 
to be done on more than one level...)

You will need to provide more details then.

-- 

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--