xsl-list
[Top] [All Lists]

Re: testing element's contents

2002-10-03 14:35:39
Nate,

At 12:56 PM 10/3/2002, you wrote:
Thanks Wendell. Thinking it over, your simple template
of

> <xsl:template match="p[not(normalize-space(.))]">
>    <xsl:apply-templates/>
> </xsl:template>

will not work, as much as I wish it would, as I am
allowing other elements such as <strong> and <em> and
I could get passed a node set like this

<p><strong>this is bold text</strong></p>

OR this

<p><em>this is bold text</em></p>

For both of those cases, they would need to get
wrapped in a p tag in the output.

The test will work for these cases.

If there are any elements that contain non-whitespace text anywhere inside your p, you'll get a wrapper with this test. You just need to decide whether this describes your requirements accurately. For example, maybe if you had

<p><ul><li>list with one item</li></ul></p>

you'd want to strip that p (whereas the test I've given will create a p in output for this). I dunno, it depends on your source and what you're doing with it.

The real point is if you can characterize your requirement more simply, you can write simpler code. Lots of overlapping tests on the presence of certain element types in certain positions make me nervous: a recipe for incompleteness, confusion and breakage under maintenance. To be avoided if possible.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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