470,833 Members | 1,391 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

Showing node-level members of a global set

ion
Hi! I'm struggling with doing this in an elegant way -- I'll get my
XSLT books out of storage this weekend, but for now I could use some
help.
<bedknob>
<broomstick>
<bippity>boppity</bippity>
</broomstick>
<broomstick>
<bippity>boppity</bippity>
<bippity>boo</bippity>
</broomstick>
</bedknob>
I'd like to get the complete list of bippities, then compare the
bippities of each broomstick to them, and make a mark for each present
member of the complete set of bippities in a particular broomstick,
like
<table>
<thead>
<tr>
<th>boppity
</th>
<th>boo
</th>
</tr>
</thead>
<tbody>
<tr>
<td>X
</td>
<td>
</td>
</tr>
<tr>
<td>X
</td>
<td>X
</td>
</tr>
</tbody>
</table>

OK. So, I use a Muenchian sort to get the unique list of bippities for
the thead element, but then to do the rows in the body, I have to go
through it again, and check each member against the set of present
values. I'm thinking of something like taking the intersection and
looking for count() = 2, but I'm having trouble making it happen.

Can you help me?

Ion

Jun 2 '06 #1
2 1004
Hi,

On Fri, 02 Jun 2006 21:54:32 +0200, ion <io********@gmail.com> wrote:
Hi! I'm struggling with doing this in an elegant wayI'd like to get the
complete list of bippities, then compare the
bippities of each broomstick to them, and make a mark for each present
member of the complete set of bippities in a particular broomstick,
like

I have no idea if this will conform to your idea of elegance (it uses
plain dumb for-each loops), but this solution seems to work:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="b" match="bippity" use="."/>
<xsl:variable name="bip"
select="//*[generate-id()=generate-id(key('b',.)[1])]"/>

<xsl:template match="bedknob">
<table>
<thead>
<tr>
<xsl:for-each select="$bip">
<th><xsl:value-of select="."/></th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="broomstick"/>
</tbody>
</table>
</xsl:template>

<xsl:template match="broomstick">
<xsl:variable name="this" select="bippity"/>
<tr>
<xsl:for-each select="$bip">
<td>
<xsl:if test=".=$this">X</xsl:if>
</td>
</xsl:for-each>
</tr>
</xsl:template>

</xsl:stylesheet>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Veni, vidi, wiki (http://www.wikipedia.org)
Jun 3 '06 #2
ion
Thanks, Joris, that works great.
Ion

Joris Gillis wrote:
Hi,

On Fri, 02 Jun 2006 21:54:32 +0200, ion <io********@gmail.com> wrote:
Hi! I'm struggling with doing this in an elegant wayI'd like to get the
complete list of bippities, then compare the
bippities of each broomstick to them, and make a mark for each present
member of the complete set of bippities in a particular broomstick,
like

I have no idea if this will conform to your idea of elegance (it uses
plain dumb for-each loops), but this solution seems to work:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="b" match="bippity" use="."/>
<xsl:variable name="bip"
select="//*[generate-id()=generate-id(key('b',.)[1])]"/>

<xsl:template match="bedknob">
<table>
<thead>
<tr>
<xsl:for-each select="$bip">
<th><xsl:value-of select="."/></th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="broomstick"/>
</tbody>
</table>
</xsl:template>

<xsl:template match="broomstick">
<xsl:variable name="this" select="bippity"/>
<tr>
<xsl:for-each select="$bip">
<td>
<xsl:if test=".=$this">X</xsl:if>
</td>
</xsl:for-each>
</tr>
</xsl:template>

</xsl:stylesheet>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Veni, vidi, wiki (http://www.wikipedia.org)


Jun 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dimitre Novatchev | last post: by
2 posts views Thread by Allan | last post: by
1 post views Thread by daz_oldham | last post: by
10 posts views Thread by npm | last post: by
12 posts views Thread by Arcticool | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.