[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: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 12 Apr 2005 16:48:15 +0100
preceding sibling
> 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:

     match="Center//text()"


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

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

 and 
> 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
http://www.saxonica.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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