471,086 Members | 1,097 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Can XSLT render the content: &lt;p&gt as html <p> rather than text?

I have an element, report which contains tags which have been
transformed. E.g. <pis &lt;p&gt

<myXml>
<report>This text has html tags in it.&lt;p&gt which but <has been
changed to &lt;&gt</report>
</myXml>

I there a way that the XSLT transformation can render the content as
html rather than text?

PS: I tried to cludge this by getting the xmlDOM, then using javascript
to get the the <reporttext but this just gives inconsistent results
(sometimes the <reportdisplays and other times I get an error telling
me that the expected item is null.

var reportTxt = getNodeText(oXmlDom.getElementsByTagName('report') );

a watch on oXmlDom.getElementsByTagName('report') shows the item is
there.

a watch on reportTxt shows no item (= null).

It's not the getNodeText() because when I do:

var reportNode = oXmlDom.getElementsByTagName('report');

I get the same, a watch on oXmlDom.getElementsByTagName('report') shows
the node is there; a watch on reportNode shows no node present.

This is just a crazy error which I can't debug.

On balance, I prefer the XSLT transform if possible.
Mar 13 '08 #1
4 11611
mark4asp wrote:
I have an element, report which contains tags which have been
transformed. E.g. <pis &lt;p&gt

<myXml>
<report>This text has html tags in it.&lt;p&gt which but <has been
changed to &lt;&gt</report>
</myXml>

I there a way that the XSLT transformation can render the content as
html rather than text?
Well the proper way to solve that is at the source, instead of escaping
the HTML markup you should insert well-formed XHTML markup, then your
XSLT stylesheet can easily copy it to the output or transform it to HTML
if needed.
If you can't do that then one approach is disable-output-escaping e.g.
<xsl:template match="report">
<div>
<xsl:value-of select="." disable-output-escaping="yes"/>
</div>
</xsl:template>
However disable-output-escaping is an optional feature that is not
supported by all XSLT processors respectively is not supported with all
XSLT uses (for instance when chaining XSLT tranformations). So you will
have to check whether it works with your XSLT processor in the setting
you use it with.

Other than that you are left with processing and parsing the text with
the escaped markup and create elements as needed, a task that is rather
difficult with the restricted string processing that XSLT/XPath 1.0 offer.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 13 '08 #2
Martin Honnen wrote:
<xsl:template match="report">
<div>
<xsl:value-of select="." disable-output-escaping="yes"/>
</div>
</xsl:template>
Thanks again. This is working in IE6 on my PC, so I hope it continues
to work with the other browsers; now that the trickiest one is OK.

However. I guess it depends on what the client has installed... It will
be a bit hit and miss.
Mar 13 '08 #3
mark4asp wrote:
Martin Honnen wrote:
> <xsl:template match="report">
<div>
<xsl:value-of select="." disable-output-escaping="yes"/>
</div>
</xsl:template>

Thanks again. This is working in IE6 on my PC, so I hope it continues
to work with the other browsers; now that the trickiest one is OK.
No, if you rely on the browser to perform the XSLT transformation then
you should not rely on disable-output-escaping. Firefox for instance
does not support it at all
<URL:http://developer.mozilla.org/en/docs/XSL_Transformations_in_Mozilla_FAQ#Can_I_do_disabl e-output-escaping.3F>
as it does not serialize the transformation result.
If you want to rely on disable-output-escaping then perform the XSLT
transformation on the server where you control the XSLT processor.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 13 '08 #4
Martin Honnen wrote:
mark4asp wrote:
Martin Honnen wrote:
<xsl:template match="report">
<div>
<xsl:value-of select="." disable-output-escaping="yes"/>
</div>
</xsl:template>
Thanks again. This is working in IE6 on my PC, so I hope it
continues to work with the other browsers; now that the trickiest
one is OK.

No, if you rely on the browser to perform the XSLT transformation
then you should not rely on disable-output-escaping. Firefox for
instance does not support it at all <url:
http://developer.mozilla.org/en/docs..._in_Mozilla_FA
Q#Can_I_do_disable-output-escaping.3Fas it does not serialize the
transformation result. If you want to rely on
disable-output-escaping then perform the XSLT transformation on the
server where you control the XSLT processor.
Point taken, but the page is working OK with IE 6 sp2 and IE7. I am
only required to get this website working with those browsers. It
doesn't work with FF, Opera or Safari. I'll change it to a server XSLT
when I have time, as I try to follow some kind of standard though my
boss just hates the mention of the word.

Mar 13 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Donald Firesmith | last post: by
2 posts views Thread by Francesco Moi | last post: by
2 posts views Thread by Jasonkimberson | last post: by
4 posts views Thread by David Lozzi | last post: by

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.