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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.