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

Whitespace text nodes near the front of mixed content

Subject: Whitespace text nodes near the front of mixed content
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Tue, 6 Nov 2007 04:22:15 +1300
 Whitespace text nodes near the front of mixed content
I'm struggling with a predicate or series of predicates that will pick out
certain text nodes. I have several stylesheets which generate HTML versions
of the input documents, but they generate unwanted whitespace in certain
circumstances. I'm afraid that they are XSL 1.0.

The input documents' DTD allows seven different elements (answer, cnote, dd,
ibody, li, step, td) to contain one or more target elements, along with
other mixed content. When we have something like the following fragment:

  <answer>
    <target/>
    <stuff>...</stuff>
    <otherstuff>...</otherstuff>
    <morestuff>...</morestuff>
  </answer>

then we get whitespace output for the whitespace text nodes which are
interspersed before, after and between the target and the various stuff
elements. Most of these are OK, but unfortunately the target element
generates no visible output and so whitespace nodes adjacent to a target
need to be suppressed - provided certain other conditions are met. The
problem involves any target(s) at the beginning of the answer (or cnote, or
dd, or ...).

I think the conditions are these (although it might be even more complicated
than I think):

A) If the current node is a whitespace text node whose parent is one of the
specified list of targetable elements (answer, cnote,...), AND

B1) If a whitespace text node precedes a target element then it should be
expressed if it has a preceding sibling (other than another target)
otherwise suppressed, OR

B2) If a whitespace text node follows a target element then it should be
expressed if there is an "earlier" NON-whitespace text node descendant of
the target's parent, otherwise (because we have still not generated any
visible output) it should be suppressed.

So:
  <xsl:template match="text()[normalize-space()='']
      [local-name(..)='answer'][????]" />

Starting with that "template" template, I obviously need to substitute
appropriate predicates for "????" in a series of suppressant templates, but
I've been frustrated by my attempts so far: it looks like position() isn't
going to be part of a working solution. And I'm sure there must be a better
way than having to spell out each one of the seven possible parents in a
separate pair of templates.

There are some remarkably clear-headed individuals on this list; can one of
them please put me out of my misery?

Cheers
Trevor

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.