I'm working with a XML file that must be TEI-compilant. The problem is about the pb (page break) milestone. It's not a new problem, but the existing solutions are so complicated and heavy that I was wondering if there was a more simple way in my case.
Let's have this XML file part :
<body>
<pb n="2"/><p>Some random text is put here</p><p>Another
paragraph starts here, and in the
middle of it<pb n="3"/> a page break occurred.</p><pb n="4"/
<p>the next paragraph begins
on a new page</p>
<p>But in the next paragraph, after<pb n="5"/>another page break, something else
happend : a note<note
type=glossary">the note content</note> and so everything
failing <pb n="6"/> because of this note.
I would like to transform the XML into this HTML :
<table>
<tr><td><p>Some random text is put here</p><p>Another paragraph starts here, and in the
middle of it</p></td><td>2</td></tr>
<tr><td><p>a page break occurred.</p></td><td>3</td></tr>
<tr><td><p>the next par graph begins on a new page</p></td><td>4</td></tr>
<tr><td><p>But in the next paragraph, after</td><td>5</td></tr>
<tr><td><p>another page break, something else happend : a note
<note type=glossary">the note content</note> and so everything's failing</td><td>6</td></tr>
<tr><td>because of this note.</td></tr>
It seems to me that it should be possible to achieve quite simply with a for-each-group. So, basically, I was trying something like that :
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/body">
<table>
<xsl:for-each-group select="descendant::*" group-starting-with="pb">
<tr><td><xsl:value-of select="current-group()"/>
</td><td><xsl:value-of select="current-group()[1]/@n"/>
</td></tr>
</xsl:for-each-group>
</table>
</xsl:template>
</xsl:stylesheet>
Obviously, it doesn't work… the result is :
<table><tr><td> Some random text is put here Another paragraph starts here, and in the
middle of it a page break occurred.</td><td>2</td></tr>
<tr><td/><td>3</td></tr><tr><td>
the next paragraph begins on
a new page</td><td>4</td></tr></table>
Am I going in a totally wrong direction ?
Many thanks for your help ! Christophe
I think you are not in wrong direction with for-each-group. Sometimes it is useful (for me) to make some "preprocessing" of input document and save it into variable for further transformation.
I have this xslt
In first step I split all elements containing
<pb>
. The variable then looks like followingOn this I apply your for-each-group statement. It produced following output