Re: Determining if the first child is a para element

Subject: Re: Determining if the first child is a para element
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 09 Nov 2000 14:41:50 +0000

At 10:15 AM 11/9/00 +0000, Jeni wrote:
So, to test whether the first child node of
the current node is an element, use:

  <xsl:if test="child::node()[1][self::*]">

Also be careful in this case that you have accounted for the possibility of any whitespace-only text nodes. So, for example, if your document read:

  <para>Here's my first child element, a para.</para>

Jeni's test above will fail on account of the whitespace-only text node preceding the para element (it contains a carriage return and two space characters).

Adjust for this by saying

<xsl:strip-space elements="CHAPTER"/>

at the top level, or altering your test (somewhat horribly) to:

<xsl:if test="child::node()[not(.=normalize-space(.))][1][self::para]">

Jeni's test for whether the first element child is a para is still good, of course, since the whitespace-only nodes won't come into play then.


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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:

Current Thread