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

RE: Testing for Missing or Empty Tags

Subject: RE: Testing for Missing or Empty Tags
From: "Schwartz, Rechell R, ALABS" <rrschwartz@xxxxxxx>
Date: Thu, 8 Jan 2004 12:42:42 -0600
xsl empty tag
Thanks, Wendell, Vasu, Michael, and David for your helpfule responses.

I am assuming that the data elements will only have text in them, and
that there
will be only one or zero elements and that there will be no white-space
issues,
so not(string(Tag)) seemed to do the trick, but I am still curiuous
about the difference between the two solutions:

Am I correct that:
1)not(Tag[normalize-space()]) will treat all blanks as if it were empty
text, whereas not(string(Tag)) will not?

2)If I had multiple sets of a given element, not(Tag[normalize-space()])
will return true for the following xml document because of the second
Tag element, while not(string(Tag)) will return false since the first
tag element has text?

<Xml>
<Tag>somevalue</Tag>
<Tag></Tag>
<Tag>Another value</Tag>
</Xml>

Thanks,
Rechell

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Thursday, January 08, 2004 12:58 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Testing for Missing or Empty Tags


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


 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.