xslt 2.0 regex iterate over captured substrings ==> regex-group(n)

R

RolfK

Dear Experts,

I got a regex which returns many captured subtrings.
My problem is that the regex is not in my hand and I need to iterate
over all cpatured substring items by the regex-group() function. This
function requires an integer argument. Unfortunately I do not know the
maximum index.

Actually I need simply to conctinate all matching substrings. But as
the max index is not known I can not do this.

What is the solution to that ?

Is there an alternative not to use xsl:analyze-string and regex-group
() ?

Tanks a lot

Rolf
 
M

Martin Honnen

RolfK said:
I got a regex which returns many captured subtrings.
My problem is that the regex is not in my hand and I need to iterate
over all cpatured substring items by the regex-group() function. This
function requires an integer argument. Unfortunately I do not know the
maximum index.

Actually I need simply to conctinate all matching substrings. But as
the max index is not known I can not do this.

What is the solution to that ?

You could use a sufficiently large enough number e.g. 200 if you assume
there are not more than 200 groups and do
string-join(for $g in 1 to 200 return regex-group($g), '')
that would concatenate all subgroups from 1 to 200 and as
regex-group(someIndex) of a not existing index or not matching index
gives a zero-length string that shouldn't change the result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top