[xsl] Union of StepPattern

Subject: [xsl] Union of StepPattern
From: Adam Van Den Hoven <Adam.Hoven@xxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 15:28:41 -0800
I need to filter an (X)HTML document to remove certain elements (We're
creating NITF which is a specific subset of HTML).

I have a situation where I need to remove the DIVs from within an LI
element. We have decided that when we encounter a DIV within an LI we are
going to replace it with a training BR if the next valid sibling is another
DIV. Otherwise we'll do nothing. Can I do the following:

	<xsl:template match="DIV[parent::LI]">
		<xsl:varible name="following-valid"
select="following-sibling::DIV|following-sibling::P|following-sibling::OL|fo
llowing-sibling::UL" />
		<xsl:apply-templates select="*|comment()|pi()|text()"/>
		<xsl:if test="$following-valid[1] =
following-sibling::DIV[1]">
			<br />
		</xsl:if>
	</xsl:template>

> Whether this works depends on whether the select in the variable returns
> everything in document order or each of the individual element types in
> document order and the individual results are accumulated together.
> Clearly I'm hoping that the select is guaranteed to return its nodes in
> document order not the axes.
> 
> We have also looked at something like:
> 
<xsl:template match="DIV[parent::LI 
			and name(preceding-sibling::*
						[name(.)='DIV'
						or name(.)='OL'
						or name(.)='UL'
						or name(.)='P'
						or name(.)='BR'
						or name(.)='EM'
						or name(.)='A'][1])='DIV']">
		<br/>

		<xsl:apply-templates select="*|comment()|pi()|text()"/>
</xsl:template>
<xsl:template match="DIV[parent::LI ]">
		<xsl:apply-templates select="*|comment()|pi()|text()"/>
</xsl:template>


> Sample input
> 
> <html><body>
> <ul>
> <li>
> <div>Something</div>
> </li>
<li>
<div>SomethingElse<div><table><tr><td>sometable</td></tr></table>
</li>
<li>
<div>Something Yet
again<div><table><tr><td>sometable</td></tr></table><div>Something More<div>
</li>
<li>
<div>Something Yet again<div><div>Something More<div>
</li>
<li>
<div>Something Yet
again<div><table><tr><td>sometable</td></tr></table><p>Some paragraph</p>
</li>
</ul>
</body></html>

> This should produce end up as:
> 
> <html><body>
> <ul>
> <li>
> Something
> </li>
<li>
SomethingElse
</li>
<li>
Something Yet again<br />Something More
</li>
<li>
Something Yet again<br />Something More
</li>
<li>
Something Yet again<p>Some paragraph</p>
</li>
</ul>
</body></html>

> Any suggestions???
> 
> 
> 
> Adam van den Hoven
> Internet Application Developer
> Blue Zone
> tel. 604.685.4310
> fax. 604.685.4391
> Blue Zone makes you interactive.(tm) http://www.bluezone.net/
> 

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


Current Thread