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() You can get the first child element using the XPath: child:* 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()[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()[self::*]"> ... </xsl:if> To test whether the first child element of the current node is a para element, use: <xsl:if test="child::*[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
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format