Re: [xsl] Is this possible in xsl ?

Subject: Re: [xsl] Is this possible in xsl ?
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 10 Aug 2001 16:16:28 +0100
Hi Anne,

> So the data is in the xml sorted in the capfiles with the info to
> which cap it belongs, but in the html I want it to sort by organism.
> Is this possible? I tried to do it with <xsl:for-each
> select="//organism"> but it doesn't work at all, all the organsims
> are repeated.

This looks like a grouping problem. You want to group the data by the
organisms that they're under. You need to create a key that indexes
the data elements by the org:

<xsl:key name="data-by-org" match="data" use="org" />

Then you can retrieve all the data elements for Organism1 with:

  key('data-by-org', 'Organism1')

You can find the names of all the organisms by going through all the
data elements in your document and finding those that are the first
data elements returned by the key for their particular value, with:

  <xsl:for-each select="//data[count(.|key('data-by-org', org)[1]) =
                               1]">
    <xsl:value-of select="org" />
    ...
  </xsl:for-each>

I'm not exactly sure what you want to do with the data elements, but
it looks like you might want to iterate over them and give some kind
of output based on the number of cap ancestors they have, so something
like:

  <xsl:for-each select="//data[count(.|key('data-by-org', org)[1]) =
                               1]">
    <xsl:value-of select="org" />
    <xsl:for-each select="key('data-by-org', org)">
      <br />
      <xsl:for-each select="ancestor::cap">
        <xsl:text>cap</xsl:text>
        <br />
      </xsl:for-each>
      <xsl:value-of select="info" /><br />
    </xsl:for-each>
    <br /><br />
  </xsl:for-each>

For more detail on the theory, have a look at
http://www.jenitennison.com/xslt/grouping/muenchian.html.

I hope that gets you started,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread