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

January 27th, 2009, 04:54 PM
|
|
Authorized User
|
|
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 70
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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
|

January 27th, 2009, 05:05 PM
|
 |
Wrox Author
Points: 12,738, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,924
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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:
|
|

January 27th, 2009, 05:21 PM
|
|
Authorized User
|
|
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 70
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |