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

Re: check for whitespace value between nodes

Subject: Re: check for whitespace value between nodes
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 20 Aug 2010 09:00:00 -0700
Re:  check for whitespace value between nodes
On Fri, Aug 20, 2010 at 8:15 AM, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
wrote:
> Hi,
>
> At 04:07 PM 8/19/2010, Liam wrote:
>>
>> On Thu, 2010-08-19 at 12:58 -0500, a kusa wrote:
>> > Hi
>> >
>> > Is there any way in XSLT to check if the value between two nodes is a
>> > whitespace?
>> >
>> > I tried normalize-space(product/text()) !=' ' but that is not working.
>> > I want tocheck if the actual value between <product> </product> is a
>> > white space.
>>
>> Whitespace is a tricky thing to get right. It's impossible to give you a
>> good answer without knowing more about what you are trying to do and
>> why, and the context, and without seeing your XSLT.
>
> Problems relating to "whitespace" are more often underspecified than not.
> XML has a definition of "white space" (any space, carriage return, line
feed
> or tab character or run of such characters), but whether your definition in
> your problem aligns exactly with XML's is a different question. And even if
> it does, there are often other questions.
>
> For example, in the problem statement here, what does "a white space" mean?
> By one reasonable reading it matches "^\s$", while another has it match
> "^\s+$" as Liam suggests. (Other readings allow strings that match
neither.)
> Does a run of whitespace characters count as "a white space"?
>
> Dimitre's XPath 1.0 solution, "product/text() and
> not(normalize-space(product/text())", works with the second of these
> definitions, since a run of whitespace is collapsed by normalize-space()
> into an empty string (and then coerced to Boolean false). That is, the test
> is refactored to (a) the text node exists (the 'product' element is not
> empty), but (b) it has no value other than whitespace characters.
>
> For the first definition, one might want
>
> B translate(product/text(),'&#xA;&#x9;',' ')=' '
>
> (in XPath 1.0). This turns any LF or TAB into a space, then sees if the
> resulting string is a single space. (Ordinarily one doesn't have to worry
> about CR since it has already been normalized by a parser. But even this
> isn't always so.)

Hi Wendell,

In fact the expression I proposed also covers your "first definition".

Do note that there is only a single definition for whitespace in the
XML Recommendation (http://www.w3.org/TR/REC-xml/#sec-common-syn) :

[3]    S    ::=    (#x20 | #x9 | #xD | #xA)+

and this is exactly what the normalize-space() function handles
(http://www.w3.org/TR/xpath-functions/#func-normalize-space):

"Summary: Returns the value of $arg with whitespace normalized by
stripping leading and trailing whitespace and replacing sequences of
one or more than one whitespace character with a single space, #x20.

The whitespace characters are defined in the metasymbol S (Production
3) of [Extensible Markup Language (XML) 1.0 Recommendation (Third
Edition)]."



--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play






>
> Cheers,
> Wendell
>
>
>
> ======================================================================
> Wendell Piez B  B  B  B  B  B  B  B  B  B  B  B  B 
B mailto:wapiez@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc. B  B  B  B  B  B  B 
B http://www.mulberrytech.com
> 17 West Jefferson Street B  B  B  B  B  B  B  B  B  B Direct Phone:
301/315-9635
> Suite 207 B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B 
B Phone: 301/315-9631
> Rockville, MD B 20850 B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  Fax:
301/315-8285
> ----------------------------------------------------------------------
> B Mulberry Technologies: A Consultancy Specializing in SGML and XML
> ======================================================================

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.