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

Re: cleaning up ill-structured html

Subject: Re: cleaning up ill-structured html
From: Niko Matsakis <niko@xxxxxxxxxxxxx>
Date: Thu, 23 Jan 2003 16:29:36 -0500
Re:  cleaning up ill-structured html
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

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.