Re: [xsl] Test for mixed content

Subject: Re: [xsl] Test for mixed content
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Sep 2007 11:26:55 -0400

As Mike and Jirka have hinted, there's a subtle but important distinction between "this element contains mixed content" and "some element of this element's type contains mixed content". The former is easy to test for, as David shows. The latter is a bit trickier, especially given how the scope for "some" and "type" might vary -- some element with the same name in the document, some element validating against a schema, etc.

Sometimes the latter can safely be treated as the former, and sometimes not. Sometimes you can't check the schema, but you can check all the elements of a given element's type in a document, and get a narrower margin of error (though not none) that way.

This is where a 2.0 feature that was discussed recently can be helpful. XSLT 2.0 can perform whitespace stripping of "insignificant" whitespace. Whitespace occurring in mixed content isn't insignificant by definition. Of course, this requires you to have an XSD or DTD.


At 07:12 AM 9/12/2007, David wrote:
> What is the best way to test if an element contains mixed content.

if mixed content means having element nodes and text nodes then

test="text() and *"

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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