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

Re: testing for child node and counting

Subject: Re: testing for child node and counting
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 06 Feb 2002 17:13:28 -0500
count child node
Alex,

At 04:52 PM 2/6/02, you wrote:
<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>

The test expression (not "text") is being evaluated, like any XPath expression, relative to a context node, which in this case will be the Row element that the template happens to be matching. You need <xsl:if test="field_c"> which is short for <xsl:if test="child::field_c">: this tests true if the context node has any field_c children.


2. I want to print at the top of the html table
   the number of <row>s that have a <field_c>
   child.

If you're creating the table in a template matching Orders, the instruction


<xsl:value-of select="count(Row[field_c])"/>

should do it. This is short for count(child::Row[child::field_c]), which counts the Row children (of your Orders context node) that have field_c children.

I hope that helps,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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