xsl-list
[Top] [All Lists]

Table Row processing pattern

2004-10-25 20:23:36
Hi,

I've an issue with Optional elements treated as tables rows in XHTML and XSL-FO.

I need to make sure an element actually exists in a document (sometimes it will sometimes it won't) before processing it as the row of a table (the table should only be there if the elements exist) otherwise I get XHTML / FO validation errors to do with empty table bodies.

Rather than stick markup around the apply-templates (and get the validation errors) or all kinds of conditional stuff in the template I presume (??) that an effective way of dealing with the problem is to nest the markup in the first match on the elements I want to make into table rows and then "reprocess" that row and all subsequent rows. My templates generally follow this pattern -

 <xsl:template match="qcr:ExemptionRow[1]">
<!-- match on the first element and generate a table header before applying a moded apply-templates to all the rows in the table -->
   <table border="0" width="100%" cellpadding="2" cellspacing="4">
           <thead>
     <tr>
       <th width="30%">LHS</th>
       <th width="30%">RHS</th>
       <th width="40%">Exclusion</th>
     </tr>
           </thead>
           <tbody>
<xsl:apply-templates select="../qcr:ExemptionRow" mode="exemptionRow"/>
           </tbody>
   </table>
 </xsl:template>

 <xsl:template match="qcr:ExemptionRow" mode="exemptionRow">
   <!-- treat all the items as table rows-->
   <tr>
     <td><xsl:apply-templates select="qcr:LhsExemptionItems"/><br /></td>
     <td><xsl:apply-templates select="qcr:RhsExemptionItems"/><br /></td>
<td><xsl:apply-templates select="qcr:ExclusionExemptionItems"/><br /></td>
   </tr>
 </xsl:template>

What I'm interested in is what could go wrong with this solution, is it an appropriate XSL style and what performance implications could it have?

Cheers,

Fraser


--
Fraser Crichton
Web Developer
SolNet Solutions Limited
L12, SolNet House, 70 The Terrace
PO Box 397, Wellington, Aotearoa / New Zealand
www.solnetsolutions.co.nz <http://www.solnetsolutions.co.nz>
DDI: 04-462-5078
Mob: 027-278-3392
Fax: 04-462-5011
email: fraser(_dot_)crichton(_at_)solnetsolutions(_dot_)co(_dot_)nz <mailto:fraser(_dot_)crichton(_at_)solnetsolutions(_dot_)co(_dot_)nz>

Attention:
This email may contain information intended for the sole use of
the original recipient. Please respect this when sharing or
disclosing this email's contents with any third party. If you
believe you have received this email in error, please delete it
and notify the sender or postmaster(_at_)solnetsolutions(_dot_)co(_dot_)nz as
soon as possible. The content of this email does not necessarily
reflect the views of SolNet Solutions Ltd.



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