xsl-list
[Top] [All Lists]

Re: [xsl] Including markup in a replace string (follow-up)

2016-10-06 10:43:30

  In my first post I asked if there was a way to trick the replace function 
so I could output markup in the replacement string. I have since solved my 
problem using xsl:analyze-string. I thought I’d post the solution since it 
involved escaping the curly braces that I was looking for.
 
Here’s a snippet of the input string. It’s from a test file so the text is 
bogus:
 
   datalines;
      {{This variable}} is the cat’s meow
 
And here’s the analize-string I used to get the results I needed:
 
  <xsl:analyze-string select="." regex="([{{]{{2}}|[}}]{{2}})">

The doubling is because curly brackets are special in XSLT attribute value 
templates. The square brackets are because curly brackets are special in 
regular expressions (to match "{" the regex needs to be either "\{" or "[{]".)

I would probably write this one as

<xsl:variable name="regex">\{\{|\}\}</xsl:variable>
<xsl:analyze-string regex="{$regex}">...

Michael Kay
Saxonica
--~----------------------------------------------------------------
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>