|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Question on preceding Text()
Thanks for your feedback, actually my ouput method is html,
that was a typo... I am generating an html document from an xml document and this portion is attempting to wrap elements withinin a center tag. I am resending the a portion of the stylesheet with the right output method. The resulting display I am aiming at is: <Center>Chapter on Testing: Testing FAQ Questions</Center> Thanks again, Besi **************************** <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/> <!--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'><center></xsl:text> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:template> </xsl:stylesheet> ***************************** <Book> <TitleHead> <TitleNum> Chapter 1. <TitleNum> <Center> Chapter on Testing: <AddText>Testing FAQ</AddText> <StrikeText>Questions</StrikeText> </Center> <Center> Chapter on Logic: <AddText>Logic FAQ</AddText> <StrikeText>Logic</StrikeText> </Center> </TitleHead> </Book>
> 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. XSLT has almost no support for generating tags, the only method to do so is the deprecated (and explictly non-portable) disable-output-escaping mechanism that you are using. If you are generating tags (that is, generating the textual markup of an XML document directly) you are far better to use a system such as perl that can treat such text as a first class object. With XSLT the model is that you should not write a start tag and a end tag as two distinct operations but rather you just create a center element node as one primitive operation. When (if) the result tree is serialised to a file this element will produce two tags but taht is only indirectly under the control of the XSLt stylesheet. 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. That sounds like you want preceding-sibling rather than preceding. Actually I notice that you are using <xsl:output method="text"/> which means that disable-output-escaping='yes' is doing nothing as no escaping is done in text output anyway. But the above comments still apply, you should use xml (or html) output method and generate element nodes not text. I can't understand your exact requirement well enough to suggest any code. What output do you want to generate from your supplied input? David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
|
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
|

Cart








