p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | 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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 27th, 2009, 04:54 PM
Authorized User
Points: 295, Level: 5
Points: 295, Level: 5 Points: 295, Level: 5 Points: 295, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 70
Thanks: 5
Thanked 0 Times in 0 Posts
Default Analyze-String and A Multiple-Match Example

I'm using Saxon 9b

I using XSLT 2.0 3rd ed as reference.

I have a string $keyVal = "<ABC>,<XYZ>" and I need to parse out the ABC and the XYZ. Note, that at run time I will not know how many comma separated <AAA> sets there will be. They will not all have 3 characters and they may contain Letters, Numbers and a Dash symbol. So, "<IB6F-3-4>,<IB6S-23-19>,<IFA2-3>" would be a perfectly general example. I would expect IB6F-3-4 and IB6S-23-19 and IFA2-3 to be the parsed results.

I have tried

<xsl:analyze-string select="$keyVal" regex="^.*?([A-Z0-9\-]+).*?$">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
</xsl:matching-substring>
</xsl:analyze-string>

Which very nicely parses the first item, but not the rest.

I'm reading the section in Chpt 5 called "A Multiple-Match Example" which I believe is what I need, but I'm not understanding what I'm reading. It seems that my regex should have called matching-substring for each pattern that matched Letters, Numbers and/or a Dash. But I'm only getting it called once.

What part am I missing?

Thanks.
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old January 27th, 2009, 05:05 PM
mhkay's Avatar
Wrox Author
Points: 12,738, Level: 48
Points: 12,738, Level: 48 Points: 12,738, Level: 48 Points: 12,738, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
Default

Your regex is anchored to the start and end of the string by virtue of the ^...$ symbols, which means the whole string either matches (once) or non-matches (once). To do a multiple match, remove the anchors and the internal repetition so it becomes regex="[A-Z0-9\-]+", and you will then find that <xsl:matching-substring> is invoked once for each maximal sequence of these characters. You then don't need to use regex-group(), you can access the matched substring as ".".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
mphare (January 27th, 2009)
  #3 (permalink)  
Old January 27th, 2009, 05:21 PM
Authorized User
Points: 295, Level: 5
Points: 295, Level: 5 Points: 295, Level: 5 Points: 295, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 70
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Yes, I see. That was my misunderstanding of how the regex worked. I've always been used to anchoring everything in other languages..

But that worked like a champ!

Thanks very much!
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RegEx to match a string only if it does'nt have a particular string within it arshsidhu BOOK: Beginning Regular Expressions 1 January 27th, 2009 05:17 PM
STRING EXACT MATCH ricespn Beginning VB 6 6 November 12th, 2007 01:18 PM
analyze-string and variables pcase XSLT 1 June 8th, 2007 05:22 PM
need to match string dynamically dipsut XSLT 2 May 25th, 2007 09:49 AM
match string in more than one line using Regex suman9730 General .NET 0 October 24th, 2006 03:27 AM



All times are GMT -4. The time now is 07:09 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc