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

RE: for-each within a for-each?

Subject: RE: for-each within a for-each?
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 6 Mar 2003 16:46:41 -0000
foreach within a foreach
Hi,

I would change your xsl:for-each approach ('pull processing') to an xsl:apply-templates ('push approach').  This basically means instead of populating your skeletal html with <xsl:value-of>'s, you will build it by matching the source xml against templates that you specify.

So, output the first part of your html:

<xsl:template match="POR">
  <TABLE BORDER="4" WIDTH="100%" VALIGN="TOP" CELLPADDING="5">
     	  <COLGROUP ALIGN="CENTER"><TH>LINE</TH><TH>QUANTITY</TH><TH>UOM</TH>
     	  <TH>PART NUMBER</TH><TH COLSPAN="2">SPEC/DATE</TH>
     	  <TH>PRICE</TH><TH>BASIS OF UNIT PRICE</TH></COLGROUP>
     	    
        <xsl:apply-templates/>

  </TABLE>
</xsl:template>

Then, each <ITEM_DETAIL> can be a row in the table:

<xsl:template match="ITEM_DETAIL">
  <tr>
    <xsl:apply-templates/>
  </tr>
</xsl:template>

By calling apply-templates, the processor will find the best matching template for each child of <ITEM_DETAIL>, so you need to write a template to output the code for each child:

<xsl:template match="PO_LINE_ITEM_NUM">
  <TD ALIGN="CENTER"><xsl:value-of select="PO_LINE_ITEM_NUM"/></TD>
</xsl:template>

You will have a load of templates, but this is A Good Thing and will provide you with a stylesheet thats scalable, importable etc... 

Up there with <xsl:variable> in the list of all-time-confusing-things for beginners is the use of xsl:for-each, it really doesnt help anyone understand the idea of how a processor applies a stylesheet.  
(IMHO it shouldnt be taught before apply-templates, but always is)

cheers
andrew

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.458 / Virus Database: 257 - Release Date: 24/02/2003
 

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


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.