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 January 27th, 2009, 04:54 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
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
 
Old January 27th, 2009, 05:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
The Following User Says Thank You to mhkay For This Useful Post:
mphare (January 27th, 2009)
 
Old January 27th, 2009, 05:21 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
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





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 04:22 PM
need to match string dynamically dipsut XSLT 2 May 25th, 2007 08:49 AM
match string in more than one line using Regex suman9730 General .NET 0 October 24th, 2006 02:27 AM





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