Re: [xsl] cleaning up ill-structured html

Subject: Re: [xsl] cleaning up ill-structured html
From: Niko Matsakis <niko@xxxxxxxxxxxxx>
Date: Thu, 23 Jan 2003 16:29:36 -0500
I can do step 1, but step 2 gives me trouble. To
formalise: how do I convert a structure structure like

<break/>+ { other+ <break/>+ }*

into

{ <p> other+ </p> }*

I fear the solution is really simple. Any ideas?


I wouldn't say it's simple. The best that I can come up with is this (note: untested), perhaps there is a more elegant solution:

<xsl:template match="break">
<!-- locate the positions of all following breaks, appending a comma after each -->
<xsl:variable name="following-breaks">
<xsl:for-each select="following-sibling::*">
<xsl:if test="self::break"><xsl:value-of select="position()"/>,</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- extract the position of the first break following sibling -->
<xsl:variable name="first-break" select="number(substring-before ($following-breaks, ','))"/>
<!-- don't do any copies if the next break occurs immediately after us -->
<xsl:if test="$first-break > 1">
<p>
<!-- copy all elements in between us -->
<xsl:copy-of select="following-sibling::*[position() < $first-break]"/>
</p>
</xsl:if>
</xsl:template>



Niko Matsakis


--
DataPower technology
http://www.datapower.com


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread