[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: a sequence of regex-group()

Subject: Re: a sequence of regex-group()
From: "Geert Bormans geert@xxxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Oct 2015 20:40:50 -0000
Re:  a sequence of regex-group()
Hi Ken,

Thanks for this.
It did not realize I could use last() and position() this way so thanks for that

However, I need access to the sequence of regex "captured" groups inside a single match in a variable sequence
so I can access them based on the capturing group number
Inside the matching-substring I will need to be able to use $re-groups[1] for regex-group(1)
because there is a nested analyze-string, so the regex-group(1) of the outer matching-substring has disappeared

Maybe I am already giving too much distracting context.
Ruby has all the capturing groups in an array or a hash,
I expected something similar, and it turned out to be more complex

I believe the context sequence you are talking about is the sequence of regex-group(0) om each match
together with the non matching substrings as seperate items interlined

Best regards

Geert


----- Original Message -----
From: "G. Ken Holman g.ken.holman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx, xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Sent: Wednesday, October 28, 2015 5:03:03 PM
Subject: Re:  a sequence of regex-group()

At 2015-10-28 15:20 +0000, Geert Bormans geert@xxxxxxxxxxxxxxxxxxx wrote:
>Hi all,
>
>sanity check
>
>If I wanted a sequence of all the regex-group() values available in 
>a matching-substring...
>
>(This is inside a function and the actual regex $re is passed in as 
>a param, so number of item() is unknown)
>
>I expected this to be somewhat more straightforward than this, so I check
>
>                 <xsl:variable name="group-count" 
> select="string-length(replace($re, '[^\(]+', ''))"/>
>                 <xsl:analyze-string select="$str" regex="{$re}">
>                     <xsl:matching-substring>
>                         <xsl:variable name="re-groups" select="for 
> $i in 1 to $group-count return regex-group($i)" as="item()*"/>
>
>
>Any thoughts?

Would it not be easier to somehow deal with the current context 
list?  Remember that analyze-string sets position() and last() for a 
sequence of matched and non-matched strings.

T:\>type temp.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   exclude-result-prefixes="xs"
   version="2.0">

<xsl:template match="/">
   <xsl:text>&#xa;</xsl:text>
   <xsl:analyze-string select="'a b c d e'" regex="\w">
     <xsl:matching-substring>
       <xsl:value-of select=".,position(),last(),'&#xa;'"/>
     </xsl:matching-substring>
     <xsl:non-matching-substring>
       <xsl:value-of select=".,position(),last(),'&#xa;'"/>
     </xsl:non-matching-substring>
   </xsl:analyze-string>
</xsl:template>

</xsl:stylesheet>
T:\>xslt2 temp.xsl temp.xsl
<?xml version="1.0" encoding="UTF-8"?>
a 1 9
   2 9
b 3 9
   4 9
c 5 9
   6 9
d 7 9
   8 9
e 9 9

I haven't looked at it in detail, but could you not determine the 
group count from the size of the context list?  Perhaps not, if you 
don't know if the first or last is matching or non-matching.

I hope this becomes helpful.  I am on a conference call and sneaking 
in this response.

. . . . . . . . Ken


--
Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
Free 5-hour lecture:  http://www.CraneSoftwrights.com/links/video.htm |
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/ |
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx |
Google+ profile:       http://plus.google.com/+GKenHolman-Crane/about |
Legal business disclaimers:     http://www.CraneSoftwrights.com/legal |


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.