xsl-list
[Top] [All Lists]

Re: [xsl] Sibling recursion?

2022-03-03 12:05:02
Dear xsl-list,

Thanks to everyone for the quick responses, and especially to Norm for
sharing the template that I should have written in the first place.

Best,

David

On Thu, Mar 3, 2022 at 11:23 AM Norm Tovey-Walsh ndw(_at_)nwalsh(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

I would be grateful for any insights.

This seems to work, YMMV.

<xsl:template match="p">
  <p>
    <xsl:for-each-group select="node()"
                        group-adjacent="self::q or
self::text()[normalize-space(.)='']">
      <xsl:choose>
        <xsl:when test="current-grouping-key()">
          <q>
            <xsl:for-each select="current-group()">
              <xsl:if test="position() gt 1">
                <xsl:text> </xsl:text>
              </xsl:if>
              <xsl:sequence select="node()"/>
            </xsl:for-each>
          </q>
        </xsl:when>
        <xsl:otherwise>
          <xsl:sequence select="current-group()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each-group>
  </p>
</xsl:template>

                                        Be seeing you,
                                          norm

--
Norman Tovey-Walsh <ndw(_at_)nwalsh(_dot_)com>
https://nwalsh.com/

We are at the very beginning of time for the human race. It is not
unreasonable that we grapple with problems. But there are tens of
thousands of years in the future. Our responsibility is to do what we
can, learn what we can, improve the solutions, and pass them
on.--Richard Feynman


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