Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2005, 12:50 AM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving text

Hello,

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

Code:
<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,
Brett

 
Old August 31st, 2005, 03:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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

<xsl:template match="par">
  <xsl:apply-templates/>
</xsl:template>

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

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

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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 31st, 2005, 10:16 AM
Registered User
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:
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,
Brett






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





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