xsl-list
[Top] [All Lists]

Re: [xsl] Regex in @select Escaping Puzzle

2020-08-16 11:06:09
Am 16.08.2020 um 17:42 schrieb Eliot Kimber ekimber(_at_)contrext(_dot_)com:
I have this element as my context element:

<p>{{image_100}}GEO_AS_MC_M01_T02_05.eps{{/image}}</p>

And I want to get the "GEO_AS_MC_M01_T02_05.eps" using analyze-string, where the value 
"image_100" could have any value where "100" is in this example.

I can't work out the way to escape the curly braces in the @regex value so my 
match works (or I can't work out what else I might be doing wrong).

Oxygen's regex search gives me the correct result with this:

\{\{image_.+}}([^{]+)\{\{/image}}

But this attempt in XSLT 3 does not work:

<xsl:analyze-string select="." regex="\{{\{{image_.+}}(.+)\{{\{{/image}}}}">

In that the non-matching substring is the entire selected string,

What regex or escaping detail am I missing?

Part of the problem I think is that the "regexp" attribute of
"xsl:analyze-string" allows attribute value templates so you either have
to double curly braces or better declare your pattern as a parameter or
variable before the element e.g. using Michael's suggestion

  <xsl:param name="pattern"
as="xs:string">\{\{image_[^}]+\}\}([^{]+)\{\{/image\}\}</xsl:param>


and then you can use

      <xsl:analyze-string select="." regex="{$pattern}">

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>