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

using a param to determine how many columns to output.

Subject: using a param to determine how many columns to output...
From: "Simon Harvey" <harvey_simon@xxxxxxxxxxx>
Date: Tue, 14 Dec 2004 17:04:35 +0000
xsl if param
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
}
}


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.