xsl-list
[Top] [All Lists]

RE: group using element in two different places in xml

2004-07-05 08:56:27
I'll just repeat an earlier thread today:

"You'll find the answer at http://www.jenitennison.com/xslt/grouping

Michael Kay"

Note that you may want to use a template approach rather than the for-each
approach. Jeni's pages will teach you all about it. Of course, if you then
still can't figger it out then you're always welcome to ask further.

HTH,
<prs/>

-----Original Message-----
From: James Steven [mailto:JSteven(_at_)redlinesoftware(_dot_)co(_dot_)uk] 
Sent: Monday, July 05, 2004 10:19 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] group using element in two different places in xml 

Hello
Currently I have a table which uses the xml and pseudo code shown below:

<a>
 <b>
  <c>
   <d>
   <data>
        <info>group1</info>
      <info2>two</info2>
      <info3>three</info4>
   </data>
   <data>
        <info>group3</info>
      <info2>four</info2>
      <info3>five</info4>
   </data>
   <data>
        <info>group1</info>
      <info2>two</info2>
      <info3>five</info4>
   </data>
   <data2>
        <info>group1</info>
      <info2>two</info2>
      <info3>four</info4>
   </data2>
   <data2>
      <info>group2</info>
      <info2>two</info2>
      <info3>five</info4>
   </data2>
   <data2>
        <info>group3</info>
      <info2>three</info2>
      <info3>four</info4>
   </data2>
    </d>
   </c>
 </b>
</a>

<xsl:key name="entries" match="data" use="info"/> <xsl:key name="entries2"
match="data2" use="info"/>  <xsl:template match="a"/>
  <xsl:for-each
select="d/data[generate-id(.)=generate-id(key('entries',info))] |
d/data2[generate-id(.)=generate-id(key('entries2',info))] ">
   <xsl:for-each select="key('entries',info)">
   <!--display value of each unique <info> as header and other elements in
<data>--!>
   </xsl:for-each>
   <xsl:for-each select="key('entries2',info)">
   <!--display other each unique <info> as header and other elements in
<data2>--!>
   </xsl:for-each>
</xsl:for-each>
</xsl:template>

The pseudo code above produces a table displaying each <data> and <data2> in
whatever <info> group it has the same value as.  The problem with this
method is that it produces each <info> group twice as <xsl:for-each> adds
both d/data and d/data2.  How do I list each unique <info> and the <data> or
<data2> that corresponds with it without duplicating?

Thanks for any help.
James









--+------------------------------------------------------------------
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>
--+--


<Prev in Thread] Current Thread [Next in Thread>