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

Re: Breaking paragraphs one linebreaks

Subject: Re: Breaking paragraphs one linebreaks
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 May 2019 15:01:06 -0000
Re:  Breaking paragraphs one linebreaks
On 09.05.2019 15:44, Manuel Souto Pico terminolator@xxxxxxxxx wrote:

Do you think I can use XSLT to do this more or less easily?

Yes, XSLT 3 can do it easily, using tokenize to split the segments and then grouping to group the different segments together:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	exclude-result-prefixes="#all"
	version="3.0">

<xsl:mode on-no-match="shallow-copy"/>

<xsl:output indent="yes"/>

<xsl:param name="lb" as="xs:string">&lt;br&gt;</xsl:param>

  <xsl:template match="tu">
      <xsl:variable name="split">
          <xsl:apply-templates mode="split"/>
      </xsl:variable>
      <xsl:for-each-group select="$split/tuv/seg" group-by="position()
mod count($split/tuv[1]/seg)">
          <tu tuid="{position()}">
              <xsl:apply-templates select="current-group()/snapshot()/.."/>
          </tu>
      </xsl:for-each-group>
  </xsl:template>

<xsl:mode name="split" on-no-match="shallow-copy"/>

  <xsl:template match="seg" expand-text="yes" mode="split">
      <xsl:for-each select="tokenize(., '(' || $lb || ')+')">
          <seg>{.}</seg>
      </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/ej9EGcD/1

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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