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

RE: Picking up the 2nd part text after child element

Subject: RE: Picking up the 2nd part text after child element
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Thu, 27 Mar 2003 10:44:51 -0000
xsl text after
I suspect your real requirement is not to process the second text node,
but to process all the text nodes. Use the standard:

<xsl:apply-templates/>

which will process all the child nodes, in turn. To do non-standard
processing of the text nodes, do, for example:

<xsl:template match="text()">
<span><xsl:value-of select="."/></span>
</xsl:template>

But usually you don't need to define a template rule for text nodes,
because the built-in rule copies the text node to the result tree, which
is usually what you want to happen.

Try to avoid using xsl:value-of when handling elements that may contain
child elements. It rarely does what you want. Use xsl:apply-templates
instead.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Spenser Kao
> Sent: 26 March 2003 23:05
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Cc: 'Spenser Kao'
> Subject:  Picking up the 2nd part text after child element
> 
> 
> Hi,
> 
> If I have an element having text split into two parts with a 
> child element in between, how do I pick up the second part 
> text after the child element?
>  
> Please see attached files for xml instance, stylesheet and 
> test output. 
> 
> I expected to pick up the multiple parts of text and the 
> child element's text in the order they appear, but lost the 
> second part text after the child element. Any suggestion will 
> be appreciated.
> 
> Regards,
> 
> Spenser
> 
> 1)  The xml instance file --
> 
> <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> 
> <paras> <p>First paragraph starts, <i>Italic text here</i>, 
> first paragraph ends.</p> 
> <p>Second paragraph starts, <i>Italic text here</i>, second 
> paragraph ends.</p> 
> </paras>
> 
> 2) The stylesheet file -
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="text"/>
> 
> <xsl:template match="/paras">
> <xsl:apply-templates select="p"/>
> </xsl:template>
> 
> <xsl:template match="p">
> 
> One para --
> <xsl:if test="text()">
> p: <xsl:value-of select="text()"/>
> </xsl:if>
> <xsl:if test="node()">
> 	<xsl:apply-templates select="i"/>
> </xsl:if>
> </xsl:template>
> 
> <xsl:template match="i">
> i: <xsl:value-of select="text()"/>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 3) The test output.
> One para --
> 
> p: First paragraph starts,
> i: Italic text here
> 
> One para --
> 
> p: Second paragraph starts,
> i: Italic text here 
> 
> 
> 
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.