Closed GoogleCodeExporter closed 9 years ago
I was able to get this working with a little modification to 2 files:
util.js and xslt.js
I noticed that just before returning the output in xsltProcess (xslt.js), the
function xmlText is used to generated my html. This function would stomp my
CDATA
section (the <b>Hello</b> World) because at this point it was tagged as text
and not
CDATA. So I thought that I could solve this by setting the cdata option to
true. This
did not quite solve it so I went into the xmlTextR function (util.js) and
modifed the
section when testing if a nodeType is DOM_TEXT_NODE. Instead of just escaping
the
text, I tested if the cdata option was flagged as true. If the cdata option was
flagged as true then I did not escape the text node.
Now when I run my code it runs as expected. Now I do not know if this hack is
the
correct way of processing the xslt but I hope that it gives a little insite
into the
problem.
I am attaching the modifed versions if you would like to take a look.
Original comment by lea...@gmail.com
on 3 Dec 2006 at 5:30
Attachments:
That solution is wrong.
There are two issue here: first, xmlEscapeText() is broken (as pointed out in
another
bug report). It only escapes the *first* occurrence of each markup character <
> &,
but not *each*. This leads to the weird lt;b>Hello</b> in the output. I'm
fixing this.
The second issue is what output to expect. It is wrong to expect a CDATA node
in the
output, because the output is generated using xsl:value-of. Cf.
[http://www.w3.org/TR/xslt#value-of]: "The xsl:value-of element is instantiated
to
create a text node in the result tree. The required select attribute is an
expression; this expression is evaluated and the resulting object is converted
to a
string as if by a call to the string function." Now, the string value of a
CDATA node
is just its text, with no character treated as markup. That is, in the output
appears
a TEXT node, not a CDATA node. Now if the nodeValue of a TEXT node contains
markup
characters, they are represented in the XML text as entity references < >
&, which is what you see.
If you want to transfer the CDATA node into the output, you have to
xsl:copy-of, as in
<xsl:template match="page/message">
<div style="color:green">
<xsl:copy-of select="node()"/>
</div>
</xsl:template>
This surfaces another problem, namely that CDATA nodes are not copied by
copy-of. I'm
fixing this too (and comment nodes are also not copied by copy-of).
Original comment by steffen....@gmail.com
on 15 Dec 2006 at 3:24
The xsl:copy problem is fixed in release-0-6, as well as the XML escaping
problem.
Original comment by steffen....@gmail.com
on 15 Dec 2006 at 8:47
Original comment by steffen....@gmail.com
on 15 Dec 2006 at 10:00
Original issue reported on code.google.com by
lea...@gmail.com
on 2 Dec 2006 at 12:34