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

Re: Re: efficiently extracting a capture group from a

Subject: Re: Re: efficiently extracting a capture group from analyze-string()
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Jun 2022 17:58:46 -0000
Re:  Re: efficiently extracting a capture group from  a
On Sat, Jun 04, 2022 at 05:22:16PM -0000, Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx scripsit:
> The tricky part is, I need an empty sequence if the input string does not
> comply with pattern.
[snip]
> 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:
>
>   my $file = 'path/my-sometype.xml';
>
>   my ($type) = ($file =~ m{my-(\w+)});

This is hard because perl is hiding a conditional in =~ and there's no
analagous XPath mechanism.

<xsl:variable name="adjust" as="xs:string" select="replace($file,'^.*my-([^\.]*).xml$','$1')" />

<xsl:variable name="type" as="xs:string?" select="if ($file eq $adjust) then '' else $adjust" />

Will do it in the same sort of conceptual pattern perl is using.

<xsl:variable name="type" as="xs:string?"
select="analyze-string($file,'my-(\w+)')/descendant::fn:group[@nr eq
'1']/string()" />

and adding fn to the namespaces declared for the stylesheet is probably
more natural for XPath.


-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

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.