xsl-list
[Top] [All Lists]

using a param to determine how many columns to output...

2004-12-14 10:04:35
Hi there,

I have written a template which matches elements and creates a table for each element which contains all the info from the XML document element I am interested in and this works fine.

The problem is that I want to be able to create another table and populate this second table's rows and columns with the tables returned by the first template I refer to above.

I have managed to stick the first set of tables in to the second but my problem comes in using a parameter to determine how many columns should appear in the table.

Usually when programming I would expect to use a for loop using the parameter as a test for a counter which would create a new row for each say 2 elements. But I can't do this in XSLT...

I had a go using the element position in the array element to try do this but am still getting nowhere...

anyone able to suggest a suitable approach to solving this?
It's very annoying to be so close to the requirement!!!!


This is the template I have made (I hope this looks ok in a browser!)

<xsl:template name="findAndExtractPageModelItemsIntoTable">
<xsl:for-each select="void">
                       <xsl:if test="string(@property)='pageItemModels'">
                       <table border="10">
<tr> <!-- with this commented in at this stage you get items within single row-->
                       <!--
number of items in the array = <xsl:value-of select="array/@length" /><br /> number of cols to display = <xsl:value-of select="$cols" /><br />
                        -->
                        <xsl:for-each select="array/void">
<!-- <tr> when this is commented in then I get new row per item, down the page--> <xsl:variable name="arrayIndex" select="@index + 1"/> arrayIndex = <xsl:value-of select="$arrayIndex" />
                                   <br />
<xsl:if test="$arrayIndex &lt;=$cols" > <td><xsl:call-template name="extractReportPageModelItem"/></td>

                                            </xsl:if>
<xsl:if test="$arrayIndex &gt;=$cols" >

<td><xsl:call-template name="extractReportPageModelItem"/></td></tr>

                                               </xsl:if>

                                   <!-- </tr> -->

                                   </xsl:for-each>

                       <!-- </tr> -->

                       </table>

                       </xsl:if>



</xsl:for-each>

</xsl:template>


the logic being:


For each void //void  is an element
{
   if (void is a "PageItem")
  {
           create table tag
                       create an open row tag

for each array/void //the element or node where I know the PageItem data is
                       {
                              if this node position <= cols
                             {
<td>call the template which returns a table itself </td>
                             }
                             if this node position >= cols
                             {
<td>call the template which returns a table itself </td><close row tag>
                              }
                        }
                   close the table tags
     }
}



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>