Subject: Re: [xsl] Re: efficiently extracting a capture group from analyze-string() From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sat, 4 Jun 2022 17:26:31 -0000 |
Hi Gerrit, Graydon,
Thanks for having a look!
The tricky part is, I need an empty sequence if the input string does not comply with pattern. replace() returns the original string for a non-match. I could address that with a prefilter:
B replace($file[matches(., '/my-(\w+)\.xml$')], '^.+/my-(\w+)\.xml$', '$1')
but I don't like duplicating patterns because they can accidentally become desynchronized. (If anyone suggests an ENTITY as a solution here, please see me after class.)
Graydon, I need your solution for obtaining the file basename elsewhere in my stylesheet -- thank you!! -- but I run into the prefilter double-pattern issue whether I replace()the full path or just the basename.
And although this example processes a filename, I'd like to find best generalized way to obtain a capture group (or nothing) for any match scenario. In perl, I can assign a variable to the result of a regex match:
B my $file = 'path/my-sometype.xml';
B my ($type) = ($file =~ m{my-(\w+)});
and I was hoping for something similar in XQuery.
Thank you everyone! It's nice to be able to group-think through this.
- Chris
XSL-List info and archive <https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__;!!A4F2R9G_pg!YXd556WaLkP4pGQ6edPoLq22GVZWXz0FWKC8B6fG3pWIEv49hMn2JEHevovei-DY16w5mb_F-bFG4sPyBrcYYJwk3mBc3dJ69yblgscpjoSpFqlrlsgk$>
EasyUnsubscribe <https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsub/xsl-list/3380743__;!!A4F2R9G_pg!YXd556WaLkP4pGQ6edPoLq22GVZWXz0FWKC8B6fG3pWIEv49hMn2JEHevovei-DY16w5mb_F-bFG4sPyBrcYYJwk3mBc3dJ69yblgscpjoSpFguJxHbP$> (by email)
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/225679> (by email <>)
-- Gerrit Imsieke GeschC$ftsfC<hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930
GeschC$ftsfC<hrer / Managing Directors: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Re: efficiently extracting a , Chris Papademetrious | Thread | Re: [xsl] Re: efficiently extractin, Chris Papademetrious |
[xsl] Re: efficiently extracting a , Chris Papademetrious | Date | Re: [xsl] Re: efficiently extractin, Chris Papademetrious |
Month |