[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Question on preceding Text()
> 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'><center></xsl:text> As DC explained, d-o-e is not the right way to do things. Michael Kay http://www.saxonica.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|