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

Wrapping consecutive similar elements inside a new par

Subject: Wrapping consecutive similar elements inside a new parent element
From: Graham Hannington <Ghannington@xxxxxxx>
Date: Fri, 14 Feb 2003 11:10:27 -0000
li wrapping
I'm cleaning up HTML exported from Word documents.  First, I run Tidy again
the exported HTML, to convert it to well-formed XHTML, then I transform it
with my own XSLT stylesheet.

I need to convert (this is slightly simplified):


<p>Some paragraph that does not begin with a span element whose first
character is a hyphen.</p>
<p><span>-</span>List item</p>
<p><span>-</span>List item</p>
<p><span>-</span>List item</p>
<p><span>-</span>List item</p>
<p>Some paragraph that does not begin with a span element whose first
character is a hyphen.</p>
<p><span>-</span>List item</p>
<p><span>-</span>List item</p>
<p><span>-</span>List item</p>
<p><span>-</span>List item</p>
<p>Some paragraph that does not begin with a span element whose first
character is a hyphen.</p>


into this:


<p>Some paragraph that does not begin with a span element whose first
character is a hyphen.</p>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
<p>Some paragraph that does not begin with a span element whose first
character is a hyphen.</p>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
<p>Some paragraph that does not begin with a span element whose first
character is a hyphen.</p>


I'm afraid my attempts at this have been truly pitiful:


	<xsl:template match="p[starts-with(span[1], '-')]">

		<xsl:if
test="not(starts-with(preceding-sibling::p[1]/span[1], '-'))">
			<xsl:text>&lt;ul&gt;</xsl:text>
		</xsl:if>

		<li>
			<xsl:apply-templates />
		</li>

		<xsl:if
test="not(starts-with(following-sibling::p[1]/span[1], '-'))">
			<xsl:text>&lt;/ul&gt;</xsl:text>
		</xsl:if>
	</xsl:template>


I know, I know: those <xsl:text>&lt;ul&gt;</xsl:text> bits are a joke, they
don't produce the <ul> parent element.

I've tried writing a template that uses <xsl:for-each>, but that ends up
grabbing all following-sibling <p> elements that begin with <span>-</span>.
I don't know how to stop the <xsl:for-each> at the first non-matching <p>
element.

Can anyone throw me an XSLT pearl?

 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.