[BNM] FAO paul p XSL...

Paul Perrin bnmlist@brightonnewmedia.org
Tue Mar 11 23:30:00 2003


I couldn't get your code to work as posted, but merged some bits with mine, inverted the member/group check and have ended up with the following (which works a treat!) - forgive the dodgy indents!.

Thanks for your (very useful) input.

It is interesting that I found /no/ sample code to filter duplicates (I had to work from scratch)... Either my search techniqes are slipping (alas altavista is not what it was :-(, and google was never good for code samples). Or XSL is very immature despite being old. Or XSL gurus are carving out a quiet market to themselves...

Regards

Paul /)/+)

<xml id="xmldata">
<groups>
<group>
<name>Top-Group</name>
<members>
	<member><name>Mathew</name></member>
	<member><name>Mark</name></member>
	<member><name>Luke</name></member>
	<member><name>John</name></member>
	<member><name>Paul</name></member>
</members>
</group>
<group>
<name>Small-Group</name>
<members>
	<member><name>Luke</name></member>
	<member><name>John</name></member>
	<member><name>Ringo</name></member>
</members>
</group>
</groups>
</xml>

<xml id="xsltdata">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
	<table>
    	<tr><th>User</th>
			<xsl:for-each select=".//group">
            	<th><xsl:value-of select="name"/></th>
            </xsl:for-each>
		</tr>
		<xsl:for-each select=".//member">
			<xsl:sort select="name" />
			<xsl:if test="not(name=preceding::member/name)">
				<tr><td><xsl:value-of select="name"/></td>
					<xsl:variable name="thisuser" select="name" />
					<xsl:for-each select="//group">
						<td><xsl:if test="members/member/name=$thisuser">X</xsl:if></td>
					</xsl:for-each>
				</tr>
			</xsl:if>
		</xsl:for-each>
	</table>
</xsl:template>
</xsl:stylesheet>
</xml>

-----Original Message-----
From: Simon Dell [mailto:simondl@epic.co.uk]
Sent: 11 March 2003 09:16
To: bnmlist@brightonnewmedia.org
Subject: [BNM] FAO paul p XSL...


At 13:47 10/03/03 +0000, you wrote:
>I have an XML document which is a dump of all the members of all of our 
>email lists.
><list>
><name>First List</name>
><members>
>         <member>user1</member>
>         <member>user2</member>
>         <member>user12</member>
></members>
></list>
><list>
><name>Second List</name>
><members>
>         <member>user1</member>
>         <member>user7</member>
>         <member>user9</member>
></members>
></list>
>
>I want to transform for a table...
>
>User    First List      Second List
>user1   X               X
>user2   X
>user7                   X
>user9                   X
>user12  X
>
>It took a day and a half to work out the six lines of XSL to select the 
>members and do a *distinct* select/sort(!). Any XSL genius fancy saving me 
>another day and a half by doing the rest? (just for the glory mind you...)

How's this?
I've not tried it...

simon

<xsl:template match="/">

         <table>
                 <tr>
                         <th>User</th>
                         <xsl:for-each select="list">
                                 <th><xsl:value-of select="name"/></th>
                         </xsl:for-each>
                 </tr>
                 <xsl:for-each select="member">
                 <xsl:variable name="listName"><xsl:value-of 
select="ascendant::list/name"/></xsl:variable>
                         <tr>
                                 <td><xsl:value-of 
select="."/></td>     <!-- get the name of the member here -->

                                 <xsl:for-each select="/list">
                                         <td><xsl:if test="name(.) = 
$listName"/>x</td>
                                 </xsl:for-each>

                         </tr>
                 </xsl:for-each>
         </table>

</xsl:template>


-8<---------------------------------
Info/Subscription/Archives -
www.brightonnewmedia.org

BNM Powered by - www.screen-play.net

25th March, Silicon Beach. 7 pm - late, @ The Sussex Arts Club. FREE.
Media & New Media Community meet & party. www.silicon-beach.com

SkillSwap - Designing for Accessibility
Mon 31st March 6pm at the CSV Training Center, BBC Building, Queens 
Road, Brighton.
The event is FREE but people must email skillswap@andybudd.com to 
confirm ASAP if they wish to attend.