Re: [xsl] XPath which tests that an element does not have mixed content?

Subject: Re: [xsl] XPath which tests that an element does not have mixed content?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 03 Nov 2011 14:59:31 -0400
I messed up by not correctly addressing the Person element ... this would be more precise:

not(normalize-space( string-join( (author,author/Person)/text() ),'')))

Avoiding the use of string-join() you could individually test each text() node:

not( (author,author/Person)/text()/boolean(normalize-space()) = true() )

... but I'm not convinced someone maintaining the stylesheet would see the effect any quicker with the above expression than the one I proposed earlier.

I hope this also helps.

. . . . . . . . Ken

At 2011-11-03 14:50 -0400, I wrote:
At 2011-11-03 18:44 +0000, Costello, Roger L. wrote:
Would you please recommend an XPath expression which ensures that the content of <author> is optional whitespace, <Person>, optional whitespace, and nothing else:

            <name>Simon L. Peyton Jones</name>

The result of the XPath expression is true if the content is as desired and false otherwise. The XPath should return true for the above example and false for the below example:

       The person is:
            <name>Simon L. Peyton Jones</name>

In XSLT 2.0 you could test the join of text() children of the cited elements along the lines of:

not(normalize-space( string-join( (author,Person)/text() ),'')))

I hope this helps.

. . . . . . . . . . Ken

Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0
Crane Softwrights Ltd.  
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile:
Legal business disclaimers:

Current Thread