[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Getting text and non-block nodes before any block nodes

Subject: [xsl] Getting text and non-block nodes before any block nodes
From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 12 Sep 2014 21:50:20 -0000

I think this is an FAQ but my situation may be slightly different. In any
case, if it's an FAQ, maybe my asking it will help.

This is in a DITA context, where I can know for any element whether it is
a block or not a block (because in DITA all elements have a base type that
is inherently block or not block).

I have the situation where a wrapper element may contain any combination
of text, non-block elements, or block elements.

I need to find either all the nodes up to the first block or determine
that there are none and get the first block.

My solution is:

<xsl:variable name="textBeforeBlocks">
  <xsl:sequence select="(text() |
<xsl:variable name="hasTextBeforeBlocks" as="xs:boolean"
  select="normalize-space(string($textBeforeBlocks)) != ''"

Where the lc:isBlock() function returns true if the element provided is a
DITA block element.

This seems to pass all my tests but I'm wondering if there's a better way
to make this check?

I also realized that I can use the $textBeforeBlocks variable to then
process any remaining blocks (because I will have already output the text
before blocks):

<xsl:when test="$hasTextBeforeBlocks">
  <xsl:apply-templates select="node() except($textBeforeBlocks)"/>

Which I think is a particularly nice example of using "except".



Eliot Kimber, Owner
Contrext, LLC

Current Thread