Re: [xsl] &lt; to < while preserving &amp;

Subject: Re: [xsl] &lt; to < while preserving &amp;
From: "Abel Braaksma (online)" <abel.online@xxxxxxxxx>
Date: Fri, 27 Jul 2007 12:13:33 +0200 (CEST)
In addition to what's already been said, you may think of one of the
following two approaches of tackling this mess:

1. Using XSLT 2.0, you can replace any &lt; and &gt; that is inside
a text using a template like this together with a copy idiom:

<xsl:template match="text()[matches(., '&gt;|&lt;']" >
   <xsl:sequence select="translate(., '&gt;&lt;', '&EF00;&EF01')" />
</xsl:template>

and apply your character maps to the private use characters &EF00;
and &EF01; respectively.

2. Using a little bit more sophisticated replace and a function,
considering that only little tags (i.e., <b>, <i> <strong> etc) are
wrongly escaped that way, you can create your own saxon:parse
replacement with a regular expression + analyze-string (use both the
matching and non-matching part). I.e., you matching regex could be
something like this:

regex="&lt;([a-z]+)&gt;(.*)&lt;/\1&gt;"

which will capture the tagname in the $1 and the content between the
tags in $2.


Cheers,
-- Abel





> Hello,
>
> <title>Me &amp; You &lt;i&gt;together&lt;/i&gt;</title>
>
> I tried my best with character-maps to get from the above
> XML the following HTML:
>
> <h3>Me &amp; You <i>together</i></h3>
>
> Is this possible? And how could it be done?
>
> Gr|_e,
>
> Kai Weber

Current Thread