1

I'd like to split a text into sections:

The source XML:

<data>
  <p>hello</p>
  <p>nice</p>
  <p>BREAK</p>
  <p>world</p>
</data>

My half successful attempt:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" >
  <xsl:output indent="yes"/>

  <xsl:template match="data">
    <xsl:for-each-group select="p" group-starting-with=".[. = 'BREAK']">
      <chapter>
        <xsl:copy-of select="current-group()"/>
      </chapter>
    </xsl:for-each-group>
  </xsl:template>
  
</xsl:stylesheet>

The result (fragment) I'd like to get:

<chapter>
  <p>hello</p>
  <p>nice</p>
</chapter>
<chapter>
  <p>world</p>
</chapter>

Instead I get

<chapter>
   <p>hello</p>
   <p>nice</p>
</chapter>
<chapter>
   <p>BREAK</p>
   <p>world</p>
</chapter>

(it still contains <p>BREAK</p>)

My question is: is there a straightforward way to get rid of the <p>BREAK</p> element?

topskip
  • 16,207
  • 15
  • 67
  • 99

1 Answers1

2

You can easily select <xsl:copy-of select="current-group()[not(. = 'BREAK')]"/>.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110