Subject: RE: more on Using apply-templates instead of for-each?
From: "Kathy Burke" <Kathy_Burke@xxxxxxxxx>
Date: Tue, 15 Apr 2003 15:00:59 -0400
|
Thank you Tom and Wendell...getting much clearer...
Tom, since you've also used value-of, may I assume this is not a case where
I can use apply-templates? Is that because I want the items in table rows?
kathy
-----Original Message-----
From: Passin, Tom [mailto:tpassin@xxxxxxxxxxxx]
Sent: Tuesday, April 15, 2003 2:51 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: more on Using apply-templates instead of for-each?
[ Kathy Burke]
> Please remember: newbie!
>
> I know Wendell's right about using apply-templates instead of
> for-each but
> I've been trying to change my structure without
> success...would appreciate
> knowing how I could adjust the following template to
> accomplish it using
> apply-templates..
It is not much different (in this case), just some re-arranging.
<xsl:template match="safety">
<table border="1" width="100%" cellpadding="4">
<tr bgcolor="red" valign="bottom">
<th align="left">
<h3>SAFETY</h3>
</th>
</tr>
<xsl:apply-templates
select="numbered_list/listitem" mode='safety'/>
</table>
<br />
</xsl:template>
<xsl:template match='listitem' mode='safety'>
<tr>
<td>
<xsl:number level="multiple" format="1. " count="listitem" />
<xsl:value-of select="." />
</td>
</tr>
</xsl:template>
Notice that I used a mode on the template for "listitem". That is so
you can process other "listitem" elements that are not in a "safety"
block differently (in case there are any) - just use a template that
matches "listitem" but has a different or no mode.
In this example, thre is not much difference between the for-each and
the apply-templates approach. It is much like using subroutines instead
of in-line code. In-line is fine for short bits of code, subroutines are
preferred for longer or more complex sections of code.
In other cases, the fact that the context is a single node (in
for-each) vs. a node-set (in apply-templates and call-templates) can
make quite a difference.
Did this answer your question?
Cheers,
Tom P
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
- more on Using apply-templates instead of for-each?
- Kathy Burke - Tue, 15 Apr 2003 14:04:55 -0400 (EDT)
- <Possible follow-ups>
- Passin, Tom - Tue, 15 Apr 2003 14:48:06 -0400 (EDT)
- Kathy Burke - Tue, 15 Apr 2003 14:56:31 -0400 (EDT) <=
- Passin, Tom - Tue, 15 Apr 2003 15:24:47 -0400 (EDT)
- Passin, Tom - Tue, 15 Apr 2003 15:31:30 -0400 (EDT)
- Passin, Tom - Tue, 15 Apr 2003 16:38:51 -0400 (EDT)
|
|