Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 31st, 2005, 12:50 AM
Registered User
Join Date: Aug 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving text


I am fairly new to XSLT, so please bear with me.

I would like to be able to access the different portions of text, split up by other elements, within an element, in order to process the whole set of code sequentially.

For example, for

<par>The first part <embedded>comes before</embedded> the second part</par>
I would like to be able to retrieve "The first part" separately from "The second part" in order to be able to process the whole set sequentally (i.e., with "comes before" displayed in between the two strings). Any idea how I might do this?

thanks very much,

Reply With Quote
  #2 (permalink)  
Old August 31st, 2005, 03:19 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Sure, this is what the standard <xsl:apply-templates/> mechanism is designed to achieve:

<xsl:template match="par">

<xsl:template match="embedded">
  .. process the "embedded" element ..

<xsl:template match="text()">
  .. process a single text node ..

Usually you can use the default (built-in) template for text nodes, which just copies the text to the result tree; but you could do your own processing here if you prefer. You can also make the match condition more selective, e.g. match="par/text()" if you want a special rule to handle text nodes appearing directly within a par element.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old August 31st, 2005, 10:16 AM
Registered User
Join Date: Aug 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Dear Michael,

Thanks very much for your help...Just to clarify then...

Once the templates are applied (for the <par> element), it will first match the text preceding the <embedded> element, then process the <embedded> element, and then the text following the <embedded> element? If that is the case, then I am confused though why this XSLT book I have says:

quote:"Be aware that the text of an element is the concatenation of all of its text nodes...if you want to provide spacing, line breaks, or other formatting, you need to use the text() node test against all the child nodes individually."
My question is then in what circumstances is text() applied individually, and when is it applied as a concatenation (whether of the text split up within a single element as the situation I originally described, or of concatenating together the text of multiple elements)?

On a related question, I am puzzled by why one even needs <xsl:for-each> since it seems that templates themselves iterate for a series of nodes sequentially as well...

thanks very, very much,

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
retrieving name of an object nerssi Javascript 2 June 13th, 2006 03:48 AM
Retrieving Cookies sabansingh ASP.NET 2.0 Basics 0 January 31st, 2006 05:26 AM
NEED HELP! retrieving from database nvillare .NET Web Services 5 October 22nd, 2004 12:37 AM
retrieving results adam69uk Dreamweaver (all versions) 1 February 16th, 2004 02:08 PM
Retrieving a value from a different frame plong HTML Code Clinic 2 December 10th, 2003 08:19 AM

All times are GMT -4. The time now is 07:59 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.