472,126 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

&lt; to < with XSLT

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:output 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
Jul 20 '05 #1
4 9507

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
Jul 20 '05 #2
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:
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

Jul 20 '05 #3

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
Jul 20 '05 #4
In article <cl**********@lacerta.tiscalinet.it>,
matatu <ma****@katamail.com> wrote:
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
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.