This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to define a xsl to display such a xml document...
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: shenjun <shjunsuper at 263 dot net>
- Cc: "XSL-List at lists dot mulberrytech dot com" <XSL-List at lists dot mulberrytech dot com>
- Date: Wed, 6 Mar 2002 10:14:22 +0000
- Subject: Re: [xsl] How to define a xsl to display such a xml document...
- Organization: Jeni Tennison Consulting Ltd
- References: <20020306091808.C98FC1CC42552@smtp.263.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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