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

using few or many templates?

Subject: using few or many templates?
From: Dan Diebolt <dandiebolt@xxxxxxxxx>
Date: Fri, 16 Mar 2001 21:36:52 -0800 (PST)
using few
I have an XML file that looks like this:

<A>
 <B>B</B>
 <C>C</C>
 <D>
  <E>E1A</E>
  <E>E1B</E>
  <F>
   <G>G1A</G>
   <G>G1B</G>
   <G>G1C</G>
  </F> 
 </D>
 <D>
  <E>E2A</E>
  <E>E2B</E>
  <F>
   <G>G2A</G>
   <G>G2B</G>
   <G>G2C</G>
  </F>
 </D>
</A>

Which I wish to convert to html and display in a table like this:

B|   |
C|   |
 |E1A| 
 |E1B| 
 |   |G1A 
 |   |G1B 
 |   |G1C 
 |E2A| 
 |E2B| 
 |   |G2A 
 |   |G2B 
 |   |G2C 


I can accomplish it in one tightly coded template:

 <xsl:template match="A">
  <table>
  <tr><td><xsl:value-of select="B"/></td></tr>
  <tr><td><xsl:value-of select="C"/></td></tr>
  <xsl:for-each select="D">  
   <xsl:for-each select="E">
    <tr><td></td><td><xsl:value-of select="."/></td></tr>
   </xsl:for-each>
   <xsl:for-each select="F/G">
    <tr><td></td><td></td><td><xsl:value-of select="."/></td></tr>
   </xsl:for-each>
  </xsl:for-each>
  </table>
 </xsl:template>

Or with multiple templates:

 <xsl:template match="A">
  <table>
  <xsl:apply-templates select="B"/>
  <xsl:apply-templates select="C"/>
  <xsl:apply-templates select="D"/>
  </table>
 </xsl:template>
 
 <xsl:template match="B">
  <tr><td><xsl:value-of select="."/></td></tr>
 </xsl:template>
 
 <xsl:template match="C">
  <tr><td><xsl:value-of select="."/></td></tr>
 </xsl:template>
 
 <xsl:template match="D">
  <xsl:apply-templates select="E"/>
  <xsl:apply-templates select="F"/>
 </xsl:template>
 
 <xsl:template match="E">
  <tr><td></td><td><xsl:value-of select="."/></td></tr>
 </xsl:template>
 
 <xsl:template match="F">
  <xsl:apply-templates select="G"/>
 </xsl:template>
 
 <xsl:template match="G">
  <tr><td></td><td></td><td><xsl:value-of select="."/></td></tr>
 </xsl:template>

Note the first xsl fragment used no apply-templates and 
the second fragment used multiple apply-templates.
My question to the list is this: As a matter of style, how
do you trade off these two extremes in coding? From the
simple to most complex situation, the issue of how to
factor your template usage must repeatedly come up.
How do you deal with this?

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

 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-2011 All Rights Reserved.