 |
| 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
|
|
|
|

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

August 28th, 2009, 05:50 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
a) how is this related to XSLT?
b) why are you asking us to do your homework for you?
|
|

August 28th, 2009, 05:55 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
its not homework, its a task that my boss gave me.
perhaps help would be nice not remarks like that
|
|

August 28th, 2009, 06:00 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

August 28th, 2009, 06:07 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
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?
|
|

August 28th, 2009, 06:12 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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).
|
|

August 28th, 2009, 06:26 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
How can you use contains and substring when you dont't know what the string contains?
|
|

August 28th, 2009, 06:36 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

August 28th, 2009, 06:44 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
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
|
|

August 28th, 2009, 06:53 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>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:
|
|
|
 |