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

Re: Finding the maximun number of nodes

Subject: Re: Finding the maximun number of nodes
From: Jiri Jirat <Jiri.Jirat@xxxxxxxxx>
Date: Fri, 05 Jan 2001 08:30:00 +0100
zvon count xsl
Hello Michael,
 here is the solution:

XSL:
========
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:variable name="maximum">
 <xsl:apply-templates select="table" mode="howmany"/>
</xsl:variable>

<xsl:template match="/">
 <table columns="{substring-before($maximum,'~')}">
  <!-- ...  -->
 </table>
</xsl:template>

<xsl:template match="table" mode="howmany">
  <xsl:apply-templates select="tr" mode="howmany">
   <xsl:sort select="count(td)" order="descending" data-type="number"/>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="tr" mode="howmany">
 <xsl:value-of select="count(td)"/>
 <xsl:text>~</xsl:text>
</xsl:template>

</xsl:stylesheet>

Output:
=======
<?xml version="1.0" encoding="utf-8"?>
<table columns="3"/>



Michael Lee wrote:
> 
> I am writing a XSLT stylesheet to transform a simple table from HTML to WML.
> However, the "columns" attribute is required for the "table" element in the
> latter format.  Therefore, I must be able to determine the maximum number of
> cells in the rows and use it as the value for the "columns" attribute.
> 
> The problem is that there is no way I can store and compare the result after
> I count the number of <td> in each <tr>.  I can do a sort and then count the
> first or last row, but then there is no way I can unsort the rows again to
> preserve the original output.
> 
> Does anyone have any idea if this problem has a purely XSLT solution?  The
> following is my input and desired output:
> 
> HTML input:
> 
> <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><td>(3,2)</td></tr>
> </table>
> 
> WML output:
> 
> <table columns="3">
>    <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>
> 
> --
> Michael Lee
> mlee@xxxxxxxxxx
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
 <name firstName="Jirka" surname="Jirat"/>
 <mail>     jiratj@xxxxxxxxx  </mail>
 <support>  http://www.zvon.org </support>
 <zvonMailingList> http://www.zvon.org/index.php?nav_id=4
</zvonMailingList>

 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.