xsl-list
[Top] [All Lists]

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

2014-09-12 16:50:39
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() |
*[not(lc:isBlock(.))])[not(preceding-sibling::*[lc:isBlock(.)])]"/>
    </xsl:variable>
<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)"/>
        </xsl:when>

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


Thanks,

Eliot

—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com

--~----------------------------------------------------------------
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>