This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Finding the maximun number of nodes


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]