473,756 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

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

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

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

function MM_preloadImage s() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.leng th,a=MM_preload Images.argument s; 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&&paren t.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.fo rms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
x=MM_findObj(n, d.layers[i].document);
if(!x && document.getEle mentById) x=document.getE lementById(n); return
x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_sw apImage.argumen ts; document.MM_sr= new Array;
for(i=0;i<(a.le ngth-2);i+=3)
if ((x=MM_findObj( a[i]))!=null){docum ent.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_swapImgResto re() { //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.sr c=x.oSrc;

}

function MM_preloadImage s() { //v3.0

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

var i,j=d.MM_p.leng th,a=MM_preload Images.argument s; 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.fr ames.length) {

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

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

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

if(!x &amp;&amp; document.getEle mentById) x=document.getE lementById(n);
return x;

}

function MM_swapImage() { //v3.0

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

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

}
</script>

Sep 25 '05 #1
4 3227
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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no" omit-xml-declaration="ye s"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d"
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#dtden try_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
3776
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"/> <xsl:template match="/"> <xsl:text>&apos; &lt; &gt; &quot; &amp;</xsl:text>
1
5581
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. I have specified <xsl:output method="html"/> and encoding="iso-8859-1". When I apply the xsl:value-of and set the disable-output-escaping to "yes", the HTML formatting tags are displayed correctly, but the French accented characters are...
3
2231
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"/> <xsl:template match="/"> <node>&apos;</node>
13
9649
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
2
4380
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 output from the stringbuilder placed at the bottom of my <BODY> section, after the top navigation menu dropdown dataset output. Currently the JavaScript is output to the top of the <BODY> section of my HTML output from the control. How can I...
6
2407
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 automation. N.B. the environment is a totally enclosed intranet, all the client machines have WinXP, IE6 and Office Pro 2003 with all the latest SPs, and the IE security settings are sufficient to allow the Local Intranet Zone to instantiate...
14
2681
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 if it is apache, or php, or just an error I am not seeing. here is the code: <?php /** * Loop through the resultset
12
10117
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) ..... // xsl contents abc.aspx?p1=v1&amp;p2=<xsl:value-of select="$v2" />
2
4307
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 file. The portion that is not working is the star rating part <?php session_start(); include_once('includes/host_conf.php'); include_once('includes/db_connect.php'); include_once('includes/mysql.lib.php');...
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.