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

Question on preceding Text()

Subject: Question on preceding Text()
From: "Besi Fube" <pearle20@xxxxxxxxxxx>
Date: Tue, 12 Apr 2005 11:08:14 -0400
fube
I am currently attempting to Wrap nodes within a center para into one center tag by checking the length of the preceding sibling. If the length of the preceding sibling is greater than Zero, then a center tag has already been opened so nothing needs to be done. Otherwise open a center tag. I have included a test xml structure and a portion of the xslt that attempts to handle this. I am using the same reverse logic to close the <Center> tag. i.e string-length(parent::*/following-sibling::*)>0

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.

Is there a better way of checking the length of the closest preceding text node that is a 'sibling' of the context node?

I attempted using
string-length(parent::*/preceding::*[1])>0
but this does not ensure that I am pulling a node that is a child of the same parent node. When I try using the reverse i.e string-length(parent::*/following::*[1])>0 to close the center tag, the tag closes right after the first text(), in this case after the sentence "Chapter on Testing:"


Thanks, I will very much appreciate any suggestions.
Besi

***********************************************
<Book>
	<TitleHead>
		<TitleNum>
			Chapter 1.
		</TitleNum>
		<Center>
			Chapter on Testing:
			<AddText>Testing FAQ</AddText>
			<StrikeText>Questions</StrikeText>
		</Center>
	</TitleHead>
</Book>



***********************************************
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:output method="text"/>
<!--Wrap Center child tags by check if the length of preceding sibling of Text parent nodes such as AddText and Strike Text within the Center tags is zero-->
<xsl:template match="text()">
<xsl:if test="ancestor::Center">
<xsl:choose>
<xsl:when test ="name(../..)='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>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


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.