Re: [xsl] if child element does not exist stop generation

Subject: Re: [xsl] if child element does not exist stop generation
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 03 May 2005 12:14:16 -0400
At 06:20 AM 5/3/2005, David wrote:
> Hi,
>          You can do this using:
>
><xsl:if test="*[self::length]"> or

That is more easily written as

<xsl:if test="length">

>  or
>
> <xsl:if test="*[name() = 'length']">

Translations from XPath short to long syntax:


"length" is short for
   "child::length"
   (set of 'length' element children of context node)

"*[self::length]" is short for
   "child::*[self::length]
   (set of element children that have a 'length' element on the self axis)

"*[name() = 'length']" is short for
   "child::*[name() = 'length']"
   (set of element children that return 'length' as the result
    of the name() function with an implicit argument of "self::node()")

The xsl:if test works by evaluating the test expression and returning a Boolean; then depending on the Boolean value, the contents of the xsl:if are processed (or not). When the result is not already a Boolean, it is "coerced" using the XPath casting rules. All these tests work because the casting rule for a node-set to a Boolean is that the set is true if it has any members, false if it is empty.

Cheers,
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 ======================================================================

Current Thread