&lt; to < with XSLT

D

David Carlisle

If your processor supports d-o-e then you can use

<xsl:value-of disable-output-escaping="yes" select="."/>

assuming the current node is the element containing your quoted string.

David
 
M

matatu

Hi to all,

I have a xml file, a substring like:

&lt;a href=&quot;#&quot;&gt;text&lt;/a&gt;

which after an xslt trasform is rendered as (using xsl:eek:utput method html):

&lt;a href="#"&gt;text&lt;/a&gt;


How can I get as xslt result the following:

<a href="#">text</a>

I cannot use CDATA for indexing problem of the original text...

thank you for any suggestion
Mark
 
M

matatu

Hi David,
thankes for your answer, but it' not possible for me because if I have
an other &lt; it must be no converted... example:

text 3&lt;4 is true as shown in the following url:
&lt;a href=&quot;#&quot;&gt;text&lt;/a&gt;

in which the first "&lt;" must be not converted before it arrives to the
browser, others they do...

David Carlisle ha scritto:
 
D

David Carlisle

grr

If possible I'd suggest not starting from there, your input is basically
broken, but if you have no control over the input then basically what
you need to do is decide on some heuristics that some piece of text
"looks like" HTML markup and so output it unquoted.

I really wouldn't use XSLT 1 for that, you want something with regexp
support, perl or XSLT2 draft (as implemented in saxon 8) or if you are
using xslt1 I'd look into whether your processor allows extension to
some language with regexp (javascript or java perhaps) just to handle
that text string.

In simple cases you could use
<xsl:value-of select="substring-before('.&lt;a href=&quot;')/>
<a href="{substring-before(substring-after('.&lt;a href'),'&quot;')}">

etc etc with lots of substring before and after, but it gets very hard
to manage such code.

David
 
R

Richard Tobin

matatu said:
thankes for your answer, but it' not possible for me because if I have
an other &lt; it must be no converted... example:

Well, how do you expect XSLT to know which should be converted? Only
you know that! You will have to make your stylesheet disable output
escaping for the ones that need to be converted, and not for the
others.

It may well be that XSLT is not the best tool for this; a generic
stream editor like sed might be better. Or perhaps you should
reconsider how your data is generated in the first place, so that it
doesn't have markup represented in the same way as ordinary text.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top