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 28th, 2009, 05:34 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default Find the string

Hello all,


can someone give me some advice on the following please:

Task #3
Finding the substring that exists after a reoccurring pattern ends when the pattern is not entirely uniform.

E.g. extracting the string after the last occurance of the pattern 'aaabbcc(any 3 to 7 characters)dddeeefff(any 2 to 4 characters)xxxyyyzzz'

For example, in the string:

Asdfkjxxyyzzhadjfhasdfkjhaaabbccs1fg2hdddeeefffsfg2xxyyzzasdfkjh asdasdi8haaabbccs1feedddeeefffmm11xxyyzz123867jhdla7s6

We want to find the substring: 123867jhdla7s6




Regards,
John
 
Old August 28th, 2009, 05:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

a) how is this related to XSLT?
b) why are you asking us to do your homework for you?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 28th, 2009, 05:55 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

its not homework, its a task that my boss gave me.

perhaps help would be nice not remarks like that
 
Old August 28th, 2009, 06:00 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well no offence, but you've got a weird boss. My boss has never assigned me a task like that.

My first question still stands - what has this got to do with XSLT?

The problem is simple string manipulation, testing if a string contains a value, and if so chopping the string in two, then testing the second part again.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 28th, 2009, 06:07 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

well you have to find the solution with xslt. I assume this is going to be a regex problem.

If its so simple can you solve it?
 
Old August 28th, 2009, 06:12 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I wouldn't bother with regex. Just use contains() and substring() and a recursive template.

And no offence, but if I solved it _for_ you then it wouldn't help you learn would it (I'm assuming that is the whole point of your boss assigning you this task).
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 28th, 2009, 06:26 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

How can you use contains and substring when you dont't know what the string contains?
 
Old August 28th, 2009, 06:36 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Huh?

contains() and substring() take parameters - those parameters can either be variables you declare or nodes whose value is used. So you pass in the node or value you want to find as two variables.

Actually, you'd probably use substring-after rather than substring, but the same logic applies.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 28th, 2009, 06:44 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

i know the functionality of contains and substring,

but you haven't helped at all.

You don't know what the string contains just that it has the pattern and you want the string after the pattern
 
Old August 28th, 2009, 06:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>extracting the string after the last occurance of the pattern 'aaabbcc(any 3 to 7 characters)dddeeefff(any 2 to 4 characters)xxxyyyzzz'

Looks to me something like

replace($in,
'.*?(aaabbcc.{3,7}dddeeefff.{2,4}xxxyyyzzz)*(.*)', '$2')
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
JohnBampton (August 28th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Matching pattern in Given String sanjivbshinde ASP.NET 2.0 Professional 3 October 10th, 2008 06:32 PM
how to find a string in another string in vb6 satish_k VB How-To 3 March 30th, 2007 12:17 PM
Find String in query vishwadh SQL Server ASP 3 September 6th, 2006 03:16 AM
syntax to find a string in a string cole SQL Server 2000 2 October 10th, 2005 06:06 PM
JSP string find characters ndanger J2EE 2 November 24th, 2004 09:52 AM





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