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

Subject: [xsl] Including markup in a replace string (follow-up)
From: "Craig Sampson craig.sampson@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 6 Oct 2016 14:28:44 -0000
Hi All,
  I am subscribed to the digest so I won't see any responses till tomorrow.

  I am running XSL 3.0

  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}})">
    <xsl:matching-substring>
      <span class="noProcess"><xsl:value-of select="regex-group(1)"/></span>
    </xsl:matching-substring>
    <xsl:non-matching-substring>
      <xsl:value-of select="."/>
    </xsl:non-matching-substring>
  </xsl:analyze-string>

To get the regex working I had to double the curly braces and surround them
with square brackets. I then doubled the curly braces around the quantifier.

Here's the result:

   datalines;
      <span class="noProcess">{{</span>This variable<span
class="noProcess">}}</span> is the cat's meow


Craig

Current Thread