XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bob RoccoSubject: Using XSL to Complete an HTML Table
Author: Bob Rocco
Date: 14 May 2007 04:28 PM
I have the following XML input which I need to use to populate an HTML table.

<MQMO>
<Order>
<blaha/>
<blahz/>
</Order>
<Order>
<blaha/>
<blahz/>
</Order>
....
....
....
</MQMO>

The <Order> elements can appear from 1 to 10 times. In the case where there is less than 10, I need to still generate an <TR> row with default values with the <TD>'s.

I currently have an <xsl:template match="Order"> which takes care of producing the rows for the existing <Order>'s. My problem is backfilling the remaining rows. I "think" I can use some sort of recursion, but I am not that familar with xsl or recursion, so I am at a loss.

Any guidance is appreciated.

Postnext
Elias HuterSubject: Using XSL to Complete an HTML Table
Author: Elias Huter
Date: 15 May 2007 02:59 AM
Hi,

you are right, it can be done via recursion.

Call the template again within itself and add 1 to a counter until the counter reaches 10.


Documentrecursion.xsl
Solution

Postnext
James DurningSubject: Using XSL to Complete an HTML Table
Author: James Durning
Date: 15 May 2007 10:43 AM
Originally Posted: 15 May 2007 10:42 AM
In your MQMO template, after applying templates to <Order> nodes,

<xsl:call-template name="fillRows">
<xsl:with-param name="rows" select="10 - count(Order)"/>
</xsl:call-template>

and add the template:
<xsl:template name="fillRows">
<xsl:param name="rows"/>
<xsl:if test="$rows &gt; 0">
<tr><td/><td/></tr>
<xsl:call-template name="fillRows">
<xsl:with-param name="rows" select="$rows - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

Postnext
Bob RoccoSubject: Using XSL to Complete an HTML Table
Author: Bob Rocco
Date: 15 May 2007 02:24 PM
James,

I plugged the code in and it works great.

One thing I noticed while stepping thru my code using the SS debugger, is that after the rows counter goes down to 0, the inner <xsl:call-template name="fillrows"> appears to be called repetitvely causing the rows counter to count back up to 10, then the "fillrows" exits completely. Is this normal behavior of a "recursive" call? Are the previously made calls simply being "unwound"?

Posttop
James DurningSubject: Using XSL to Complete an HTML Table
Author: James Durning
Date: 16 May 2007 11:08 AM
Originally Posted: 16 May 2007 11:07 AM
Yes, each call to the function doesn't finish off until they get all the output from their calls, so the output is just returning to the calling function. Eg if you had 7 rows originally and needed to fill in the remaining 3, you'd notice it go from 3 -> 2 -> 1 -> 0, back to 1, back to 2, back to 3.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.