This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: get immediat preceeding node, if it is a comment
- From: "Andrew Welch" <awelch at piper-group dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 4 Oct 2002 11:31:00 +0100
- Subject: RE: [xsl] get immediat preceeding node, if it is a comment
- Reply-to: xsl-list at lists dot mulberrytech dot com
Or, I suppose, you could include what weve been seeing on the other
thread and use normalize-space() to bypass whitespace-only nodes:
<xsl:if
test="preceding-sibling::node()[normalize-space()][1][self::comment()]">
...
</xsl:if>
This way you dont need to use xsl:strip-space.
Notice how the positional predicate follows the normalize-space()
predicate. Im not too sure about this, maybe someone can confirm what I
say here:
preceding-sibling::node()[1][normalize-space()][self::comment()]
This will select the immediately preceding-node, should that return true
for normalize-space() and self::comment().
preceding-sibling::node()[normalize-space()][1][self::comment()]
This will select the first in a list of nodes that return true for
normalize-space() and self::comment().
So the former will only ever test the immediately preceding node, while
the latter will test all preceding-siblings because the positional
predicate isn't the first.
cheers
andrew
> -----Original Message-----
> From: Andrew Welch
> Sent: 04 October 2002 11:01
> To: xsl-list@lists.mulberrytech.com
> Subject: RE: [xsl] get immediat preceeding node, if it is a comment
>
>
>
> > - how to get the immediat preceeding node, when you don't
> > know what it will
> > be (element, comments, and for extension PIs, text())
>
> preceding-sibling::node()[1]
>
> > - how can I filter comments from it
>
> <xsl:if test="preceding-sibling::node()[1][self::comment()]">
> ....
> </xsl:if>
>
> Don't forget though that most likely the immediate preceding element
> will be some presentational whitespace, so you will need to strip that
> out using:
>
> <xsl:strip-space elements="*"/>
>
> or a more specific selection in place of * (unless of course, you are
> using msxml which strips it all out regardless).
>
> cheers
> andrew
>
>
> > -----Original Message-----
> > From: Paul Terray [mailto:terray@4dconcept.fr]
> > Sent: 04 October 2002 10:23
> > To: xsl-list@lists.mulberrytech.com
> > Subject: [xsl] get immediat preceeding node, if it is a comment
> >
> >
> > Hello,
> >
> > I have a little problem, which I am unable to find the
> > solution because I
> > must think to devious...
> >
> > I have a XML with some comments on the nodes, just before,
> > that I want to get.
> >
> > My problem is : there are not always there, so I cannot just use
> > "preceding-sibling::comment()[1]".
> >
> > Therefore, 2 questions :
> > - how to get the immediat preceeding node, when you don't
> > know what it will
> > be (element, comments, and for extension PIs, text())
> > - how can I filter comments from it
> >
> > Thanks in advance.
> >
> > --
> > Paul TERRAY - Ingénieur Systèmes Documentaires
> > 4Dconcept
> > Centre d'affaires - 22, rue Etienne de Jouy
> > 78353 Jouy en Josas CEDEX
> > Tel. 01 34 58 70 70 - Fax. 01 39 46 06 90
> > email : terray@4dconcept.fr
> >
> >
> > XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
>
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/10/2002
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list