RE: [xsl]Problem with Position()?

Subject: RE: [xsl]Problem with Position()?
From: "Geert Josten" <geert.josten@xxxxxxxxxxx>
Date: Sat, 13 Oct 2007 18:46:06 +0200
Dear Alice,

The problem lies in the fact that white-space is counted as contents of
the book element as well. You haven't specified a DTD nor a Schema that
states otherwise, so white-space is considered significant. Contents of
the book element is numbered as follows:

Book:
1. white-space
2. first p element
3. white-space
4. second p element
5. white-space

You can circumvent this problem by not using <xsl:apply-templates />,
which selects node() implicitly, which means: process all contents,
including character data and (significant) white-space as well. Instead,
you can use the select attribute of xsl:apply-templates and force to
evaluate only elements:

<xsl:apply-templates select="*" />

Or even stronger, only p child elements:

<xsl:apply-templates select="p" />

Kind regards,
Geert

>


Drs. G.P.H. Josten
Consultant



Daidalos BV
Source of Innovation
Hoekeindsehof 1-4
2665  JZ  Bleiswijk
Tel.: +31 (0) 10 850 1200
Fax: +31 (0) 10 850 1199
www.daidalos.nl
KvK 27164984


De informatie - verzonden in of met dit emailbericht - is afkomstig van
Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit
bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit
bericht kunnen geen rechten worden ontleend.


> From: Abel Braaksma [mailto:abel.online@xxxxxxxxx]
> Sent: zaterdag 13 oktober 2007 18:25
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl]Problem with Position()?
>
> Jay Bryant wrote:
> >
> > Try changing the test to use the preceding-sibling axis, thus:
> >
> > <xsl:when test="count(preceding-sibling::p) = 0">
> >
> > That test catches the first p in a series of neighboring p elements.
> >
>
>
> Be aware that with large input files and with a
> not-too-optimizing processor, this test might perform
> quadratic. If that happens, you can try changing it to:
>
> <xsl:when test="not(preceding-sibling::p[1])">
>
> which will behave the same but is easier optimized by the processor.
>
> A note to the OP: in your xsl:otherwise statement you have na
> added xsl:if which seems redundant there because it tests for
> the inverse of the xsl:when. If so intended, you can remove it.
>
> Cheers,
> -- Abel Braaksma

Current Thread