Re: [xsl] XSLT: question re testing for possibly empty elements

Subject: Re: [xsl] XSLT: question re testing for possibly empty elements
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Aug 2004 12:40:45 -0400
Ralph,

At 05:17 AM 8/17/2004, you wrote:
I guess what the original author really meant was to check if the element is "empty or non-white" - because the data stored in anElement would be a car's license number and it makes no sense to return spaces (which are invisible on the print-out) when there's alternative data stored (which he retrieves in the otherwise-branch).

I reckon my test with normalize-space() is more accurate.

I concur. (Well it's not more accurate, but it is better.)


This is not only because of what you say, but also because the construction "string-length(.) &gt; 0" is extremely common in XSLT written by programmers who are heedlessly applying idioms from other languages, not being aware that XSLT doesn't require such gyrations.

Another similar case is the use of name tests such as "local-name()='p'" instead of the simpler XPath "self::p". Other languages require grabbing names for testing the types of things; XSLT has its own ways (more elegant and concise IMO). Due to a wrinkle in XPath, one sometimes has to do name testing on attributes (which can't be checked for their type using the self:: axis), but other than that name testing is generally redundant and un-XSL-like.

Even though these work, I always correct them when I see them (if only in my head).

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