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

RE: Determining if the first child is a para element

Subject: RE: Determining if the first child is a para element
From: kenb@xxxxxxxxxxx
Date: Thu, 9 Nov 2000 11:36:13 -0800
xsl if test self
Awesome.  Just what I was looking for.  Thanks.

-----Original Message-----
From: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx]
Sent: Thursday, November 09, 2000 2:16 AM
To: kenb@xxxxxxxxxxx
Cc: XSL-List@xxxxxxxxxxxxxxxx
Subject: Re: Determining if the first child is a para element


Ken,

> I've looked at the FAQ which describes how to determine if a node has a
> single child element, but I need to know if the first child of a node is
an
> element (para, in this case).  The test needs to be done in the parent's
> <template> element, prior to an <apply-templates/>.  Is there a
> straightforward <if> test I can use for this case?  Thanks!

It's not clear whether you want to know whether it's a specific
element (a para element) or an element rather than some other type of
node (e.g. text or a comment).

You can get the first child node using the XPath:

  child::node()[1]

You can get the first child element using the XPath:

  child:*[1]

You can test whether something is an element using the test:

  self::*

You can test whether something is a para element using the test:

  self::para

So, you can find the first child node that is an element using the
XPath:

  child::node()[1][self::*]

If the first child node is not an element, then no nodes will be
selected with this XPath.  Within an xsl:if test, a node set with no
nodes in it evaluates as false() while one that does hold nodes
evaluates as true().  So, to test whether the first child node of
the current node is an element, use:

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

To test whether the first child element of the current node is a para
element, use:

  <xsl:if test="child::*[1][self::para]">
     ...
  </xsl:if>
  
I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.