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

Re: test for a empty node

Subject: Re: test for a empty node
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 29 Apr 2001 17:04:44 +0100
xsl check for empty node
Hi Tanz,

> 1. I would prefer the output to look like this
> street,
> city,
> state,
> postalCode

I guess that you mean you want to have a carriage return rather than
just a space after each comma.  You can either write them in literally
with:

<xsl:value-of select="concat(street, ',
', city, ',
', state, ',
', postalCode)" />

Or you can use a character entity like:

<xsl:value-of select="concat(street, ',&#xA;', city, ',&#xA;',
                             state, ',&#xA;', postalCode)" />

There's no difference between the two as far as the XSLT processor is
concerned.
                             
> 2. Is there way to check that if a "state" does not exist i.e.
> <state></state> (as in xml) to return:

So you mean that the value of state is an empty string rather than
that the element state doesn't exist?  You can check whether the value
of state is an empty string with:

  state = ''

or:

  not(string(state))

To get the output that you want, you need to split up the xsl:value-of
and insert an xsl:if:

  <xsl:value-of select="concat(street, ',&#xA;', city, ',&#xA;')" />
  <xsl:if test="string(state)">
     <xsl:value-of select="concat(state, ',&#xA;')" />
  </xsl:if>
  <xsl:value-of select="postalCode" />

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.