This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Nesting for-each elements - Can it be done?
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] Nesting for-each elements - Can it be done?
- From: "Chris Eckert" <ceckert at bendcable dot com>
- Date: Thu, 16 Aug 2001 15:55:19 -0700
- References: <C9B574ABCF10D511AFF70090279CC73CA2AD82@emailwa3.asymetrix.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
1. First, update the MSXML processor to the XSLT compliant version. See the
FAQ at http://www.netcrucible.com/xslt/msxml-faq.htm.
This isn't why your transformation is failing, but most subscribers to the
list use XSLT (not the MS specific dialect TR-WD)
2. The 2nd for-each is not matching any elements because their is no
web_seminars child element of the current context node. The first for-each
makes the context the web_seminars element. The second for-each is looking
for the web_seminars child of the web_seminars element. None exists, so
nothing is displayed.
3. You really should be using apply-templates instead of for-each. I have
included a sample transformation that uses both, to illustrate the
apply-templates approach.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table border="0" cellspacing="5" cellpadding="0" width="350"
bgcolor="#EEEEEE">
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="seminar">
<tr>
<td colspan="2" valign="top">
<i><xsl:value-of select="seminar_topic"/></i><br />
Presented by <xsl:value-of select="seminar_speaker/speaker_name"/>,
<xsl:value-of select="seminar_speaker/speaker_title"/>,
<xsl:value-of select="seminar_speaker/speaker_affiliation"/>
<hr size="1" width="100%" />
</td>
</tr>
<tr>
<td valign="top">
Available Dates (Select One):
</td>
<td valign="top">
<xsl:for-each select="seminar_dates/individual_date">
<xsl:element name="input">
<xsl:attribute name="type">radio</xsl:attribute>
<xsl:attribute name="name">seminar_date</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="." /></xsl:attribute>
</xsl:element>
<xsl:value-of select="." /><br />
</xsl:for-each>
</td>
</tr>
<tr>
<td colspan="2" valign="top">
<hr size="1" width="100%" />
<i>Note:</i> All Web Seminars begin at 11:00AM US Pacific Time (2:00PM
US Eastern Time).
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Have fun,
Chris Eckert
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list