Re: [xsl] Including markup in a replace string

Subject: Re: [xsl] Including markup in a replace string
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 7 Oct 2016 07:17:44 -0000
Using disable-output-escaping is always a bad idea unless there are very good
reasons indeed, which isn't the case here.

The reason is that it only works if your transformation is immediately
followed by serialization, and that immediately reduces the flexibility and
reusability of your XSLT code. Transformations rarely happen in isolation,
they are usually executed as part of a pipeline, and constructing a pipeline
immediately becomes more difficult if you have to serialize the output of one
step and the re-parse it as input to the next.

It can look like a tempting short-cut, but you (or your successors) will
regret it.

Michael Kay
Saxonica


> On 7 Oct 2016, at 05:40, Vishnu vishnu@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi Craig,
>
> I think we should use "disable-output-escaping="yes"" here.
>
> Below is the code for expected output.
>
> <xsl:value-of select="replace($pattern,'(\{\{|\}\})','&lt;span
class=&quot;noProcess&quot;&gt;$1&lt;/span&gt;')"
disable-output-escaping="yes"/>
>
>
> Regards,
> Vishnu
>
> From: Craig Sampson craig.sampson@xxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Thursday, October 6, 2016 6:40 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Including markup in a replace string
>
> Hi All,
>   I have code examples in some doc that are post processed in AngularJS. In
some cases the code examples include {{ or }} which is significant to
Angular. I have a simple replace that I am using to wrap a no-process span
around the curly braces so the Angular process will ignore them.
>
>   <xsl:value-of select="replace(.,'(\{\{|\}\})','&lt;span
class=&quot;noProcess&quot;&gt;$1&lt;/span&gt;')"/>
>
>   The only problem is that the character entity is being output as a
character entity instead of less-than and greater-than characters.
>
>   Is there a way to trick replace into outputting the less-than and
greater-than characters?
>
>   Ive tried entering the actual characters  doesnt work. Ive tried
escaping the characters with backslashes  doesnt work either.
>
>   So unless theres a way to trick replace Ill have to try analyze-string
and see if I can get what I need there.
>
> Thanks,
>   Craig
>
> Heres an example of what I need:
>
> <span class="noProcess">{{</span>This variable<span
class="noProcess">}}</span>
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <x-msg://179/-list/778978> (by email
<applewebdata://AAC29083-3BB7-4D94-B8C2-47B7734FD943>)
> "This e-mail and any attachments transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential , proprietary or
privileged information. If you are not the intended recipient, please contact
the sender by reply e-mail and destroy all copies of the original message. Any
unauthorized review, use, disclosure, dissemination, forwarding, printing or
copying of this e-mail or any action taken in reliance on this e-mail is
strictly prohibited and may be unlawful."
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <-list/293509> (by email <>)

Current Thread