xsl-list
[Top] [All Lists]

Re: [xsl] tricky text and structure test is troubling me

2020-03-06 11:28:05
On Fri, 2020-03-06 at 16:39 +0000, Trevor Nicholls
trevor(_at_)castingthevoid(_dot_)com wrote:
[...]

The number of such elements is finite, in fact off the top of my head
targets and footnotes are the only ones.

Some quick thoughts:

Consider writing a template mode that will remove footnote and target
elements, and will replace an "include" element by its contents (and
process that recursively with apply-templates of course).

(in XSLT 3 it can be a separate stylesheet invoked with fn:transform()
instead of a mode, which makes for easier testing)

So then it's a case of selecting everything before the first section
element - maybe in the template for title:

<xsl:if test="z:has-text(
  following-sibling::*[
    not(
      self::section or preceding-sibling::section
    )
   ] ) />

Now, z:has-text is a function you write that takes a list of elements
(note: if you need to match text nodes as well, it's probably easier to
use the << and >> operators on node()).

It'll pre-process them to remove footnotes etc., and then do something
like,
  <xsl:sequence select="not( empty( $proprocessed-nodes//text() ) )" />
to return true or false.

Liam

-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Web-slave, antique illustrations:  http://www.fromoldbooks.org
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>