[Home] [By Thread] [By Date] [Recent Entries]

Subject: Counting Child Nodes
From: "bix xslt" <bix_xslt@xxxxxxxxxxx>
Date: Tue, 26 Nov 2002 22:38:26 +0000
All,

As I've been developing my xsl scripts, I've realized that it would be beneficial to be able to write my xslt in such a way that it would dynamically format my page for an optimal view based on a few factors. Essentially, I have a very large table which contains data from its child node and its grandchild node. An example xml file would be:

<data><text>Title for web page</text>
   <data><text>Motivation</text>
       <data><text>White Pages</text></data>
       <data><text>References</text></data>
   </data>
   <data><text>Requirements</text>
       <data><text>Software</text></data>
       <data><text>Hardware</text></data>
   </data>
   <data><text>Design</text>
       <data><text>Interfaces</text>
           <data><text>Hardware/Software</text></data>
           <data><text>Legacy Software</text></data>
       </data>
       <data><text>Functions</text></data>
   </data>
   <data><text>Implementation</text></data>
   <data><text>Verification</text></data>
   <data><text>Documentation</text></data>
   <data><text>Archive</text></data>
</data>

Note that there are 7 <data> elements that are children of the root node. In my table, I could display each one in their own row or column, but I would prefer to put three children on the first and second lines, and then a single child on the third line. An example of this would be:

One per column:
[Motivation] [Requirements] [Design] [Implementation] . .. . .


   One per row:
       [Motivation]
       [Requirements]
       [Design]
       .
       .

   Optimal View:
       [Motivation]            [Requirements]    [Design]
       [Implementation]    [Verification]        [Documentation]
                                   [Archives]

The algorithm I would use to determine how many rows and columns would be as follows:
T = Total number of children
R = Number of children displayed per row
C = Number of columns needed


   <!-- find T -->
   T = ??

   <!-- initialize the values -->
   set R = 1
   set C = T

   <!-- setup a loop to find the best numbers -->
   while ( R < C and C > 1 )
       R = R + 1
       C = C - 1

<!-- numbers should now be close to optimal, so start displaying -->


So, my question is two-fold: How do I find T, and is there a slick way of converting the psuedo code above into XSLT?


Thanks,
Bix





_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail



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



Current Thread
  • Counting Child Nodes
    • bix xslt - Tue, 26 Nov 2002 17:34:01 -0500 (EST) <=
      • Jorge A. Salido - Tue, 26 Nov 2002 17:58:52 -0500 (EST)
      • Ritu - Tue, 26 Nov 2002 18:01:35 -0500 (EST)
      • Greg Faron - Tue, 26 Nov 2002 18:03:38 -0500 (EST)
        • Paul - Tue, 26 Nov 2002 20:32:09 -0500 (EST)
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member