Hi,
On Tue, 28 Jun 2005 14:28:54 +0200, Kerschhofer Alexander
<al*******************@siemens.com> wrote:
Honestly this is a quite interesting but however a guru-stylesheet
It would take a guru to code a guru-stylesheet:D Mine was probably
unintelligable...
and I don't understand exactly how it works. What is the recursion-rule?
The recursion is done via the 'copy_tail' template
Maybe there is a chance to get it explained :).
see the comments below
Unfortunately I had made a mistake in my example since the "new" text group
must be started after a br[@clear-previous="true"]. The example below is
corrected now. So what need to be modified?
In that case it becomes much easier, it was actually the error in your
sample data that made the job challenging.
Here you have a new stylesheet with comments included:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="before_br" match="node()[not(self::br)]"
use="generate-id(following-sibling::br[1])"/>
<!-- the key connects all nodes to their first 'br' element
following-sibling -->
<xsl:template match="body">
<xsl:copy>
<xsl:apply-templates select="br"/>
<xsl:if test="br[last()]/following-sibling::node()">
<!-- handle left-over nodes at the body's end-->
<p>
<xsl:apply-templates select="br[last()]" mode="copy_tail"/>
<xsl:copy-of select="br[last()]/following-sibling::node()"/>
</p>
</xsl:if>
</xsl:copy>
</xsl:template>
<xsl:template match="br">
<p>
<xsl:apply-templates select="." mode="copy_tail"/>
<!-- copy the tail of this 'br' node inside a 'p' element-->
</p>
</xsl:template>
<xsl:template match="br" mode="copy_tail">
<!-- continue copying the tail backwards and only stop when the
'clear-previous' attribute is 'true'-->
<xsl:apply-templates
select="preceding-sibling::br[1][not(@clear-previous='true')]"
mode="copy_tail"/>
<xsl:copy-of select="key('before_br',generate-id())"/>
</xsl:template>
</xsl:stylesheet>
regards,
--
Joris Gillis (
http://users.telenet.be/root-jg/me.html)
Vincit omnia simplicitas
Keep it simple