[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Finding the maximum number of nodes (Redux)

Subject: RE: Finding the maximum number of nodes (Redux)
From: "Pepping, Simon (ELS)" <S.Pepping@xxxxxxxxxxx>
Date: Mon, 15 Oct 2001 09:51:55 +0200
pepping
Marty McKeever wrote:
> So here is my XPath solution, submitted for comment.
> 
> The XML:
> 
> <table>
> <tr><td>1.1</td><td>1.2</td></tr>
> <tr><td>2.1</td><td>2.2</td><td>2.3</td></tr>
> <tr><td>3.1</td></tr>
> </table>
> 
> The Desired Result:
> 
> <table>
> <tr><td colspan="3">Table Header Text</td></tr>
> <tr><td>1.1</td><td>1.2</td></tr>
> <tr><td>2.1</td><td>2.2</td><td>2.3</td></tr>
> <tr><td>3.1</td></tr>
> </table>
> 
> The XSLT:
> 
> <xsl:template match="table">
> <table border="1"><tr><td>
> <xsl:attribute name="colspan"><xsl:value-of 
> select="count(tr[count(td) &gt;
> count(following-sibling::tr[count(td) &gt;
> count(preceding-sibling::tr[last()]/td)]/td)][count(td) &gt;
> count(preceding-sibling::tr[last()]/td)]/td)"/></xsl:attribute>
> Table Header Text</td></tr>
> <xsl:copy-of select="tr"/>
> </table>
> </xsl:template>

For this table it does not work:

<table>
<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></tr>
<tr><td>4.1</td><td>4.2</td><td>4.3</td></tr>
<tr><td>5.1</td><td>5.2</td></tr>
</table>

This is the resulting html:

<table border="1">
<tr><td colspan="5">Table Header Text</td></tr>
<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></tr>
<tr><td>4.1</td><td>4.2</td><td>4.3</td></tr>
<tr><td>5.1</td><td>5.2</td></tr>
</table>

This is an account of what the stylesheet does:

1
1 2 3
1
1 2 3
1 2

count(tr[count(td) &gt;
 count(following-sibling::tr[count(td) &gt;
  count(preceding-sibling::tr[last()]/td)]/td)][count(td) &gt;
count(preceding-sibling::tr[last()]/td)]/td)

1: 1 > 
   2: 3 > 1
   3: 1 > 1 no
   4: 3 > 1
   5: 2 > 1 
   -----------
   3 + 3 + 2 = 6 no

2: 3 >
   3: 1 > 1 no
   4: 3 > 1
   5: 2 > 1 
   -----------
   3 + 2 = 5 no

3: 1 >
   4: 3 > 1
   5: 2 > 1 
   -----------
   3 + 2 = 5 no

4: 3 >
   5: 2 > 1 
   -----------
   2 yes

5: 2 >
   -----------
   0 yes

===

4: 3 > 1 
5: 2 > 1
--------
3 + 2 = 5

It is a heuristic at best. count(preceding-sibling::tr[last()] is
always the first tr. following-sibling::tr[count(td) &gt;
count(preceding-sibling::tr[last()]/td)] may contain several rows,
which does not seem a good idea in an algorithm that tries to find the
maximum number of cols. Similarly for the final set of tr.

Simon Pepping
Elsevier Science
s.pepping@xxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.