This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: testing for child node and counting
- From: "Joerg Heinicke" <joerg dot heinicke at gmx dot de>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 6 Feb 2002 23:08:07 +0100
- Subject: Re: [xsl] testing for child node and counting
- References: <20020206215221.82777.qmail@web14510.mail.yahoo.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
> <Orders>
> <Row att="...">
> <field_a>...</field_a>
> <field_b>...</field_b>
> </Row>
> <Row att="...">
> <field_a>...</field_a>
> <field_b>...</field_b>
> <field_c>...</field_c>
> </Row>
> ...
> </Orders>
>
>
> 1. I want to go through each <row> and create
> an html table row only if <row> contains a
> <field_c> child. I've tried this but it
> didn't work:
>
> <xsl:for-each select="Orders/Row">
> <xsl:if text="Orders/Row/field_c">
>
> <tr>
> <td><xsl:value-of select="field_c"/></td>
> </tr>
>
> </xsl:if>
> </xsl:for-each>
<xsl:for-each> is changing the context, so you are already in <Row>-elements
and can not test on Orders/Row/field_c, but only field_c:
<xsl:for-each select="Orders/Row">
<xsl:if test="field_c">
<tr>
<td><xsl:value-of select="field_c"/></td>
</tr>
</xsl:if>
</xsl:for-each>
This can be shorten if you combine the if-statement with the
select-statement of for-each:
<xsl:for-each select="Orders/Row[field_c]">
<tr>
<td><xsl:value-of select="field_c"/></td>
</tr>
</xsl:for-each>
> 2. I want to print at the top of the html table
> the number of <row>s that have a <field_c>
> child.
<xsl:value-of select="count(Orders/Row[field_c])"/>
> Thanks in advance for any help.
> -alex
Regards,
Joerg
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list