This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Finding the maximun number of nodes
- To: mlee at kanhan dot com
- Subject: Re: [xsl] Finding the maximun number of nodes
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Date: Fri, 5 Jan 2001 01:47:59 -0800 (PST)
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Here's the solution with variable number of tables -- you can
parameterise it as an exercise... :o)))
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
>
<xsl:key name="numCells" match="tr" use="count(td)"/>
<xsl:template match="/">
<xsl:value-of select="count(//table[@ID='1']/tr[not(key('numCells',
count(td) + 1)[parent::table[@ID='1']] )]/td)"/>
</xsl:template>
</xsl:stylesheet>
Given the following input:
<tables>
<table ID="1">
<tr><td>(1,1)</td></tr>
<tr><td>(2,1)</td><td>(2,2)</td><td>(2,3)</td></tr>
<tr><td>(3,1)</td><td>(3,2)</td></tr>
</table>
<table ID="2">
<tr><td>(1,1)</td></tr>
<tr><td>(2,1)</td><td>(2,2)</td><td>(2,3)</td></tr>
<tr><td>(3,1)</td><td>(3,2)</td><td>(3,3)</td><td>(3,4)</td></tr>
</table>
</tables>
it produces:
3
Cheers,
Dimitre.
Michael Lee wrote:
Dimitre's solution makes use of <xsl:key>, something that I am not
familiar
with. However, I believe it still doesn't work if the stylesheet has
to
handle an unknown number of tables.
Michael Lee
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list