Showing node-level members of a global set

I

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
 
J

Joris Gillis

Hi,

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:eek:utput 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,
 
I

ion

Thanks, Joris, that works great.
Ion

Joris said:
Hi,

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:eek:utput 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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top