This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to define a xsl to display such a xml document...


Hi Sjoy,

> Here, Group controls several Keyword, and the Members are
> corresponded to Keywords attribute id.
>
> I want to display all members of one group into one td of table. How
> can I do that?

First, I'd set up a key so that it's easy to retrieve the Keyword with
a particular id, from its id:

<xsl:key name="keywords" match="Keyword" use="@id" />

With that key defined, you can do:

  key('keywords', 1)

to get all the Keyword elements in the document whose id attribute has
the value '1'.

Then, for each Group:

  <xsl:for-each select="content/Groups/Group">
    ...
  </xsl:for-each>

You want to create a td:

  <xsl:for-each select="content/Groups/Group">
    <td>
      ...
    </td>
  </xsl:for-each>

In which you go through the Member elements one by one:

  <xsl:for-each select="content/Groups/Group">
    <td>
      <xsl:for-each select="Member">
        ...
      </xsl:for-each>
    </td>
  </xsl:for-each>

And get the value of the Keyword whose id is equal to the value of the
current Member:

  <xsl:for-each select="content/Groups/Group">
    <td>
      <xsl:for-each select="Member">
        <xsl:value-of select="key('keywords', .)" />
      </xsl:for-each>
    </td>
  </xsl:for-each>

You might want to put some extra HTML in there, but I hope that shows
the basic method.
  
Cheers,

Jeni

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]