[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Finding the maximum number of nodes (Redux)
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) > > count(following-sibling::tr[count(td) > > count(preceding-sibling::tr[last()]/td)]/td)][count(td) > > 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) > count(following-sibling::tr[count(td) > count(preceding-sibling::tr[last()]/td)]/td)][count(td) > 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) > 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|