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

Re: Empty String

Subject: Re: Empty String
From: Greg Martel <gregm@xxxxxxxxxxx>
Date: Tue, 23 Oct 2001 17:32:43 -0500
check empty string
Wendell--your way works better (surprise). The subtleties of XSL are the hardest part for a beginner: two apparently analogous templates produce such different results. (and it's usally manifested in differing whitespace--amazing).


<xsl:template match="String">
  <!-- matches elements named 'String' -->
  <!-- processes the children of the element -
       - text, other elements, whatever -->
  <xsl:if test="not(string(.))">
    <!-- passes the test if the string content is empty -->
    <xsl:value-of select="'&#xA;'"/>
    <!-- adds a linefeed character -->

Other tests are possible, but this one is a good one. Note that this will test "true" if your String element contains other elements, but no text.

If you want to catch whitespace-only strings as well as zero-length strings, change the test to "not(normalize-space(.))". But note that such whitespace is also passed along by the apply-templates preceding the test.

I hope I construed correctly what you meant by "a String element that is empty".

This is actually a FAQ, but a hard one to document since the answer is always "it depends".

Hasta la vista,

At 04:04 PM 10/23/01, you wrote:
How do i say this using xsl: "xsl, if you find a String element that is empty, please add a text element that contains a paragraph return." I am having trouble matching the empty string.

Thanks Muchos,

Greg Martel
Coordinator of Enchiladas

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

-- Thanks Muchos,

Greg Martel
Coordinator of Enchiladas

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

Current Thread


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.
First Name
Last Name
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.