Re: [xsl] Testing for Missing or Empty Tags

Subject: Re: [xsl] Testing for Missing or Empty Tags
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 08 Jan 2004 12:57:56 -0500
Maybe Rechell wants

<xsl:if test="not(Tag[normalize-space() or *]">...</xsl:if>

or the same leaving out the "or *" if she already knows there will never be an element inside the Tag element, or doesn't care if there is.

string(Tag), alas, checks to see whether the first Tag element child has a string value (not the empty string). This may or may not be useful depending on the data (do Tag elements appear clustered or are they always alone?). It also doesn't address the empty string issue, and will test true on <Tag> </Tag> (which is not always wanted).

Whenever this question comes up, it turns out the answer depends on what the OP means by "empty" elements. If Rechell wants to assure that there is present a Tag child that includes some kind of text not whitespace, not(Tag[normalize-space()] will do that: it checks whether there does (not) exist a Tag element child with a non-empty string value. But David has already pointed out that this will fail on <Tag><some/></Tag>. Only Rechell can say whether that case should be in or out.... :->

Cheers,
Wendell

At 10:30 AM 1/8/2004, David wrote:
XSLT has no access to the tags in the document.

the test <xsl:if test="not(Tag)" would test if there are any Tag element
node children of the current node,


<xsl:if test="not(Tag[1]) or Tag ='' ">


is the same as


<xsl:if test="not(Tag) or Tag ='' ">


and tests if there is no Tag element or if some empty Tag element has
empty string value, so it would be true on

<x><Tag><y/></Tag></x>


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


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread