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 June 17th, 2010, 12:31 PM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default Extract 5 word before and after an element

Hi All,

I have XML content for text content validation. I really have no idea on what XSLT function has to be used; Sorry! for not adding any tried out XSL codes. Any one can sharing a small hint on what function is to be used would help be more .

Input:
<p>This is a paragraph First Second Third 4 Five <cv>many words and more words<cv> six seven 8 nine ten the paragraph ends

Expected Output:
<p>This is a paragraph
<td>First Second Third 4 Five</td><td>many words and more words</td>
<td>six seven 8 nine ten</td>
the paragraph ends</p>

Any help would be grateful.
__________________
Thanks,
Rocxy.
 
Old June 17th, 2010, 01:04 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please tell us whether you are looking for an XSLT 2.0 or 1.0 solution. With XSLT 2.0 you could process the preceding-sibling and following-sibling, tokenize them and then wrap the tokens you want to wrap.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 17th, 2010, 01:10 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you only want the words, then (assuming XSLT 2.0) something of the form tokenize(following-sibling::text(),'\W')[position() lt 6] or tokenize(preceding-sibling::text(),'\W')[position() gt last()-5] should do the trick. However, this loses the separators between the words. If it's necessary to retain the separators as well as the words, then a more complex solution using xsl:analyze-string is called for.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 9: Element[user control] is not a known element Arya BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 December 20th, 2009 07:31 AM
extract data from one big text element JohnBampton XSLT 12 August 23rd, 2009 08:43 AM
Extract information from MS Word by VC++ avinashss VB How-To 1 November 28th, 2007 08:41 AM
Extract embedded documents in the word document ayyanarj General .NET 0 August 31st, 2007 12:32 AM
Extract data from Word Document(RTF format) PaulJH Access 2 September 19th, 2006 07:52 AM





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