Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling HTML tags in XSL
    primarykey
    data
    text
    <p>Before I explain the problem I'm facing, I probably need to explain the problem I wanted to solve in the first place. :)</p> <p>I have an XML that will be formatted with XSL. This XML contains HTML tags in CDATA, for example:-</p> <pre><code>&lt;doc&gt; &lt;![CDATA[ &lt;b&gt;Hello!&lt;/b&gt; ]]&gt; &lt;/doc&gt; </code></pre> <p>When XSL performs the transformation, the browser displays <code>&lt;b&gt;Hello!&lt;/b&gt;</code> rather than rendering the word <b>Hello!</b> in bold. I inspected the source code, and it looks like this:-</p> <pre><code>&lt;doc&gt; &amp;lt;b&amp;gt;Hello!&amp;lt;/b&amp;gt; &lt;/doc&gt; </code></pre> <p>To solve this problem, I'm thinking of using JQuery to render the text as HTML, like this:-</p> <pre><code>$(document).ready(function(){ var obj = $(".content"); alert("text: " + obj.text()); // to test if JQuery works obj.html(obj.text()); }); </code></pre> <p>So, I tried adding the JQuery library into XSL, and after couple of attempts and reading about the problem with <code>&lt;script&gt;</code> tag, it seems like I need to add a dummy between the opening and closing <code>&lt;script&gt;</code> tag, like this:-</p> <pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"&gt; &lt;xsl:comment/&gt; &lt;/script&gt; </code></pre> <p>The rendered display shows 2 errors in Firebug:-</p> <pre><code>b.style is undefined (function(a,b){function ci(a){return d...a:a+"px")}}),a.jQuery=a.$=d})(window); $ is not defined </code></pre> <p>... and the javascript statements above doesn't work at all, not even the alert prompt.</p> <p>I decided to downgrade JQuery from 1.5.2 to 1.3.2 to see if that fixes anything. Now, I'm getting this error from Firebug:-</p> <pre><code>K.style is undefined (function(){var R=/((?:\((?:\([^()]+\)...,typeof K==="string"?K:K+"px")}})})(); </code></pre> <p>The good news is I'm getting the alert prompt with JQuery 1.3.2. The bad news is <code>obj.html(obj.text());</code> doesn't do anything.</p> <p>Just out of curiosity, I change <code>obj.html(obj.text());</code> to <code>obj.text("Just Testing: " + obj.text());</code>, which is a dumb test, but it works... I'm seeing <code>Just Testing:</code> being inserted into the actual content.</p> <p>How do I get <code>obj.html(obj.text());</code> to work here? Or a more general question is, how do I get the HTML tags from CData to render as HTML and not as text?</p> <p>Thanks much.</p> <p><strong>UPDATE</strong></p> <p>I did another test... <code>obj.html("aaa");</code> doesn't work either. I'm starting to believe it has something to do with the XSL transformation that prevents JQuery from working properly. I'm still using 1.3.2 here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload