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

RE: Question on preceding Text()

Subject: RE: Question on preceding Text()
From: "Besi Fube" <pearle20@xxxxxxxxxxx>
Date: Tue, 12 Apr 2005 14:01:18 -0400
latex string
Thanks for your feedback it was very helpful.
On the xslt, the statment:
was valid only when test="../parent::Center" .
I was not accounting for a case where test="parent::Center"
in which case I also needed to check for
based on my tree structure.

Thanks again,

----Original Message Follows----
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE:  Question on preceding Text()
Date: Tue, 12 Apr 2005 16:48:15 +0100

> The problem I seem to be having with this is that text() for
> instance the
> text "Chapter on Testing:" can not be considered a
> preceding-sibling of
> <AddText>Testing FAQ</AddText> even though they have the same
> <Center>
> parent tag since preceding-sibling does not grab the text node.

In your example the text node "Chapter on Testing:" is indeed a
preceding-sibling of the element node <AddText>Testing FAQ</AddText>,
so the problem must be somewhere else.

Note that preceding-sibling::* only selects elements, to select text nodes
use preceding-sibling::text(), and to select both using
preceding-sibling::node(). You probably only want the immediately preceding
sibling, which is preceding-sibling::node()[1].

However, if you select a text node then its string-length will always be >0.
Zero-length text nodes do not exist. Perhaps you really want to test for the
existence of the text node rather than its length? Fortunately, though,
string-length() applied to an empty node-set returns 0.

> <xsl:template match="text()">
> 	<xsl:if test="ancestor::Center">

Better to incorporate that in the match pattern:


> <xsl:choose> > <xsl:when test ="name(../..)='Center'

Better to write that as test="../parent::Center"

> string-length(parent::*/preceding-sibling::*)>0">
> 				<xsl:text> </xsl:text>
> 			</xsl:when>
> 			<xsl:otherwise>
> 				<xsl:text
> disable-output-escaping='yes'>&lt;center&gt;</xsl:text>

As DC explained, d-o-e is not the right way to do things.

Michael Kay

Current Thread


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.
First Name
Last Name
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.