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

Re: Wrapping nodes outside tables into paragraphs

Subject: Re: Wrapping nodes outside tables into paragraphs
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 May 2014 19:54:43 -0000
Re:  Wrapping nodes outside tables into paragraphs
On Thu, May 22, 2014 at 07:19:02PM -0000, Martynas JuseviD
ius martynas@xxxxxxxxxxxx scripsit:
> I have TEI markup where nodes (text nodes and some elements) are
> interspersed with table and figure elements, like this:
>   <note>
>     text text <ref type="whatever">text</ref>
>     <table>...</table>
>     text text
>     <figure>...</figure>
>     text text
>     <table>...</table>
>     <table>...</table>
>     text text
>   </note>
> There can be nodes before, between, and after tables.
> I want to produce a corresponding XHTML while also wrapping all the
> nodes between tables into <p>, so they're on the same block-level (for
> simplicity, lets say <xhtml:img> is also block-level):

This is a classic use case for XSLT 2.0's for-each-group instruction.

Are you using 2.0?

If so, an approach like

<xsl:for-each-group select="note/node()" group-adjacent="if
(self::table) then 'table' else 'interstitial'">

        <xsl:when test="current-grouping-key() eq 'table'">
            <!-- do what you do to tables -->
        <xsl:when test="current-grouping-key() eq 'interstial'>
            <!-- wrap everything else -->
            <!-- you should never get here; die loudly -->


ought to work.  (The pattern also extends.)

If you have to individual wrap adjacent tables you may want a different
grouping attribute, and you might want to select
note/node()[normalize-space()] instead, to avoid white-space only text

-- Graydon

Current Thread


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.
First Name
Last Name
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.