This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: complex XPATH test
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] complex XPATH test
- From: Wendell Piez <wapiez at mulberrytech dot com>
- Date: Mon, 16 Jul 2001 19:03:24 -0400
- Reply-To: xsl-list at lists dot mulberrytech dot com
Adam,
<xsl:template match="br">
<!-- 1st, retrieve the block ancestor you're worried about -->
<xsl:variable name="containing-block"
select="(ancestor::p|ancestor::li|ancestor::blockquote)[last()]"/>
<!-- (you'll have to extend that list to include all the possible
blocks) -->
<!-- now, figure out what text nodes are actually following inside the
block -->
<xsl:variable name="text-following">
<xsl:for-each
select="$containing-block//text()[.=current()/following::text()">
<xsl:value-of select="."/>
</xsl:for-each>
<!-- now, include the br if there's anything there besides white space -->
<xsl:if test="normalize-space($text-following)">
<xsl:copy-of/>
</xsl:if>
</xsl:template>
(untested)
It's slow and painful, but then those <br> elements are painful too.
What do you think? I'd like to see a slick solution, too....
Cheers,
Wendell
At 06:11 PM 7/16/01, you wrote:
>Hey guys,
>
>I'm working on an transform that will take well formed HTML and convert it
>into a different prose schema (NITF).
>
>I'm trying to do some intelligent filtering of valid, but meaningless HTML
>markup (the DHTML Edit control will occasionally give me stuff I'm not too
>happy aobut).
>
>If I have a <br> tag inside a block element, I only want to deal with it if
>its not the last br tag. An example
>
>I care about the br in :
><p> this is some text<br />
>here is some more</p>
>
>but not in:
><p>this is a little bit of text<br /></p>
>
>My original test was
><xsl:template match="br">
> <xsl:if test="count(following-sibling::node()) > 0">
> <br/>
> </xsl:if>
></xsl:template>
>
>but I ran into a problem with the following:
>
><p><strong>this is some bolded text<br/></strong>Some more text</p>
>
>since the br was getting ignored.
>
>What I want to do is test that the context node is not the last child of the
>context node's ancestor block node. Its also not the case that immediate
>parent of that block node will be <body> since <li> is a block node and is a
>child of <ol> or <ul>.
>
>Any thougths?
>
>Adam van den Hoven
>Internet Software Developer
>Blue Zone
>tel. 604 685 4310 ext. 260
>fax 604 685 4391
>
> > Blue Zone makes you interactive. http://www.bluezone.net/
> >
> >
> >
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list