472,971 Members | 2,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XSL output method to XML & JavaScript problem

When the output method is set to xml, even though I have CDATA around
my JavaScript, the operaters of && and < are converted to XML character
entities which causes errors in my JavaScript. I know that I could
externalize my JavaScript, but that will not be practical throughout
this application. Is there any way to get around this issue? Xalan
processor. Stripped down stylesheet below along with XHTML output.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
encoding="iso-8859-1" />

<xsl:template match="/">
<html>
<head>
<!-- CALL HEAD FILES -->
</head>
<body>
<script type="text/javascript">
<![CDATA[

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr;
for(i=0;a && i < a.length && (x=a[i]) && x.oSrc;i++)x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return
x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}
]]>
</script>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
Here is the outputted code:

<script type="text/javascript">
function MM_swapImgRestore() { //v3.0

var i,x,a=document.MM_sr;

for(i=0;a &amp;&amp; i &lt; a.length &amp;&amp; (x=a[i]) &amp;&amp;
x.oSrc;i++)x.src=x.oSrc;

}

function MM_preloadImages() { //v3.0

var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i&lt;a.length; i++)

if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

function MM_findObj(n, d) { //v4.0

var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))&gt;0&amp;&amp;parent.frames. length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&amp;&amp;d.all) x=d.all[n]; for
(i=0;!x&amp;&amp;i&lt;d.forms.length;i++) x=d.forms[i][n];

for(i=0;!x&amp;&amp;d.layers&amp;&amp;i&lt;d.layer s.length;i++)
x=MM_findObj(n,d.layers[i].document);

if(!x &amp;&amp; document.getElementById) x=document.getElementById(n);
return x;

}

function MM_swapImage() { //v3.0

var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i&lt;(a.length-2);i+=3)

if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}

}
</script>

Sep 25 '05 #1
4 3156
I think I found the solution. I put <xsl:comment> tags around the CDATA
tags and that seemed to work. I would be interested if this is the
right way to go though.

Sep 25 '05 #2


johkar wrote:
I think I found the solution. I put <xsl:comment> tags around the CDATA
tags and that seemed to work. I would be interested if this is the
right way to go though.


Well you will have the script code commented out then if an XML parser
parses it.

But your example code

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
encoding="iso-8859-1" />

<xsl:template match="/">
<html>

seems to indicate that you are not writing XHTML anyway as you are not
using the proper XHTML namespace at all e.g.
<html xmlns="http://www.w3.org/1999/xhtml">

Not sure why you think then you want output method="xml" and an XHTML
1.0 document type declared but probably you are just on the wrong path
with XHTML 1.0 use instead of HTML 4.01 for text/html. See
<http://www.hixie.ch/advocacy/xhtml>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 25 '05 #3
Thank you for the reply, information and link Martin. I guess I have
read some of this before, but for the "average" web guy trying to do
what is right it sure is confusing. All the "tableless layout" CSS
gurus recommend XHTML. I validate content with both Dreamweaver and
at W3C.

One other thing, isn't the namespace "applied" if not declared?
<html xmlns="http://www.w3.org/1999/xhtml">

Thanks again

Sep 25 '05 #4

johkar wrote:
One other thing, isn't the namespace "applied" if not declared?
<html xmlns="http://www.w3.org/1999/xhtml">


Applied by whom? The external DTD
<http://www.w3.org/TR/xhtml1/dtds.html#dtdentry_xhtml1-strict.dtd_html>
defines
xmlns %URI; #FIXED 'http://www.w3.org/1999/xhtml'
thus if you have a validating parser reading that DTD then yes, that
attribute is then added.

Only browsers like Opera or Mozilla do not use a validating parser thus
if you want to serve them XHTML as real XML and understand that an
element in your document is an element in the XHTML namespace then your
markup has to have the namespace declaration.

The XML namespaces recommendation
<http://www.w3.org/TR/REC-xml-names/#ns-using> warns:

"This constraint may lead to operational difficulties in the case
where the namespace declaration attribute is provided, not directly in
the XML document entity, but via a default attribute declared in an
external entity. Such declarations may not be read by software which is
based on a non-validating XML processor. Many XML applications,
presumably including namespace-sensitive ones, fail to require
validating processors. For correct operation with such applications,
namespace declarations must be provided either directly or via default
attributes declared in the internal subset of the DTD."

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 25 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Derek Fountain | last post by:
Just asked a question regarding this little bit of XSL: --- <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> ...
1
by: Lisa | last post by:
I need to apply the HTML formatting tags and the French accented characters in a XML document. The XML is generated from a database that has HTML tags and French accented characters in the records....
3
by: Joris Gillis | last post by:
Hi everyone, I have this stylesheet: <?xml version="1.0" encoding="ISO-8859-1" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/>...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
2
by: Hawk | last post by:
I have a custom menu control that I am creating using C#. I am rendering HTML from a StringBuilder in my control to add the needed JavaScript to the HTML output. I need to have the JavaScript...
6
by: Mark Rae | last post by:
Hi, My client has asked me to provide a "quick and dirty" way to export the contents of a DataGrid to both Excel for analysis and Word for editing and printing, so I'm investigating client-side...
14
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
2
by: bips2008 | last post by:
The code seems to work fine in other browser but in IE it throws this error. This is very urgent for me and any help would be greatly appreciated For your convienence i have posted the code for the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.