RE: [saxon] regex-group question

There's no obvious way to find out the number of matching subgroups. Testing
regex-group()="" doesn't really work, because a group can be empty even if
it exists.
You can probably do it with an extension function, something along the lines
of
public static Integer numberOfRegexGroups(XPathContext context) {
RegexIterator ri = context.getCurrentRegexIterator();
if (ri = null) return null;
return new Integer(Aggregate.count(ri.getAnother()));
}
Let me know if that works.
I'm not sure what you mean by finding out the "regex-group index". There's
no concept of a current regex-group.
Michael Kay
http://www.saxonica.com/
_____
From: saxon-help-admin@...
[mailto:saxon-help-admin@...] On Behalf Of jeff isenhart
Sent: 04 February 2005 23:53
To: saxon-help@...
Subject: [saxon] regex-group question
Is there a way to find out the regex-group index or total at runtime? Here
is what I've hacked so far.
<xsl:analyze-string select="$input"
regex="{$regex}">
<xsl:matching-substring>
<xsl:variable name="values">
<!-- I would love to know the total groups and/or the current
group index.
(not the same size all the time)
Using a loop for now - be nice if I could use $i.. -->
<!-- Build a csv string .. -->
<xsl:for-each select="for $i in (1 to 10) return $i">
<xsl:if test="not(string-length(regex-group(.)) = 0)">
<xsl:value-of select="regex-group(.)"/><xsl:value-of
select="','"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:text></xsl:text>
<xsl:value-of select="$values"/>
<xsl:text></xsl:text>
</xsl:matching-substring>
</xsl:analyze-string>
Thanks for any suggestions,
Jeff

Thread view

Is there a way to find out the regex-group index or total at runtime?
Here is what I've hacked so far...
=20
<xsl:analyze-string select=3D"$input"
regex=3D"{$regex}">
<xsl:matching-substring> =20
<xsl:variable name=3D"values">
<!-- I would love to know the total groups and/or the
current group index.
(not the same size all the time)=20
Using a loop for now - be nice if I could use $i.. -->
<!-- Build a csv string .. -->
<xsl:for-each select=3D"for $i in (1 to 10) return $i">
<xsl:if test=3D"not(string-length(regex-group(.)) =3D 0)">
<xsl:value-of select=3D"regex-group(.)"/><xsl:value-of
select=3D"','"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:text></xsl:text>
<xsl:value-of select=3D"$values"/>
<xsl:text></xsl:text>
</xsl:matching-substring>
</xsl:analyze-string>
=20
Thanks for any suggestions,
=20
Jeff

There's no obvious way to find out the number of matching subgroups. Testing
regex-group()="" doesn't really work, because a group can be empty even if
it exists.
You can probably do it with an extension function, something along the lines
of
public static Integer numberOfRegexGroups(XPathContext context) {
RegexIterator ri = context.getCurrentRegexIterator();
if (ri = null) return null;
return new Integer(Aggregate.count(ri.getAnother()));
}
Let me know if that works.
I'm not sure what you mean by finding out the "regex-group index". There's
no concept of a current regex-group.
Michael Kay
http://www.saxonica.com/
_____
From: saxon-help-admin@...
[mailto:saxon-help-admin@...] On Behalf Of jeff isenhart
Sent: 04 February 2005 23:53
To: saxon-help@...
Subject: [saxon] regex-group question
Is there a way to find out the regex-group index or total at runtime? Here
is what I've hacked so far.
<xsl:analyze-string select="$input"
regex="{$regex}">
<xsl:matching-substring>
<xsl:variable name="values">
<!-- I would love to know the total groups and/or the current
group index.
(not the same size all the time)
Using a loop for now - be nice if I could use $i.. -->
<!-- Build a csv string .. -->
<xsl:for-each select="for $i in (1 to 10) return $i">
<xsl:if test="not(string-length(regex-group(.)) = 0)">
<xsl:value-of select="regex-group(.)"/><xsl:value-of
select="','"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:text></xsl:text>
<xsl:value-of select="$values"/>
<xsl:text></xsl:text>
</xsl:matching-substring>
</xsl:analyze-string>
Thanks for any suggestions,
Jeff