Subject: Re: Determining if the first child is a para element From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 9 Nov 2000 10:15:41 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Determining if the first child , David Carlisle | Thread | Re: Determining if the first child , Wendell Piez |
Re: calling vb functions in xsl, Jeni Tennison | Date | Using client side XSLT to create SV, Lassi Lehto |
Month |