473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Using JavaScript with XML and XSL

Is it possible to use JavaScript with XML and XSL?
I tried the following but it does not work.. anything missing?

test.xml file:
--------------
<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<REPORT>

<FOOTER>
<FIELD id="errors">
<KEY>Error Code</KEY>
<VALUE>2000145</VALUE>
</FIELD>
<FIELD id="configuration">
<KEY>DEBUG</KEY>
<VALUE>TRUE</VALUE>
</FIELD>
</FOOTER>

</REPORT>

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

<HTML>
<BODY bgcolor="palegoldenrod">

<SCRIPT LANGUAGE="javascript">
<!--
function seeFooter_onclick()
{
footer1.style.display = "none"
}
//-->
</SCRIPT>

<INPUT id="seeFooter" type="checkbox" LANGUAGE="javascript"

onclick="seeFooter_onclick()">FOOTER</INPUT>
<TABLE id="footer1" bgcolor="#d1d2d2" border="1" width="100%">
<xsl:for-each select="REPORT/FOOTER/FIELD">
<TR>
<TD width="40%"><xsl:value-of select="KEY"/></TD>
<TD><xsl:value-of select="VALUE"/></TD>
</TR>
</xsl:for-each>
</TABLE>

</BODY>
</HTML>

</xsl:template>
</xsl:stylesheet>

The basic requirement is on the click of checkbox the <TABLE> should
disappear. But when i click the checkbox, browser generates an error.

I might also be posting this in the wrong newsgroup, so the pointer to
the right also would help

Regards
Fareeda
Jul 23 '05 #1
2 1656


fareeda wrote:
Is it possible to use JavaScript with XML and XSL?
What you have below is simply some script in the HTML result document of
an XSLT transformation, that shouldn't pose any problems different from
using script directly in an HTML document.
I tried the following but it does not work.. anything missing?

test.xml file:
--------------
<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<REPORT>

<FOOTER>
<FIELD id="errors">
<KEY>Error Code</KEY>
<VALUE>2000145</VALUE>
</FIELD>
<FIELD id="configuration">
<KEY>DEBUG</KEY>
<VALUE>TRUE</VALUE>
</FIELD>
</FOOTER>

</REPORT>

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

<HTML>
<BODY bgcolor="palegoldenrod">

<SCRIPT LANGUAGE="javascript">
<!--
function seeFooter_onclick()
{
footer1.style.display = "none"
}
//-->
</SCRIPT>

<INPUT id="seeFooter" type="checkbox" LANGUAGE="javascript"

onclick="seeFooter_onclick()">FOOTER</INPUT>
<TABLE id="footer1" bgcolor="#d1d2d2" border="1" width="100%">
<xsl:for-each select="REPORT/FOOTER/FIELD">
<TR>
<TD width="40%"><xsl:value-of select="KEY"/></TD>
<TD><xsl:value-of select="VALUE"/></TD>
</TR>
</xsl:for-each>
</TABLE>

</BODY>
</HTML>

</xsl:template>
</xsl:stylesheet>

The basic requirement is on the click of checkbox the <TABLE> should
disappear. But when i click the checkbox, browser generates an error.


Which browser is that, Mozilla or Netscape?
To make your script work with DOM compliant browsers like
Mozilla/Netscape you should use

function seeFooter_onclick () {
if (document.getElementById) {
var footer = document.getElementById('footer1');
if (footer && footer.style) {
footer.style.display = 'none';
}
}
}

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
fareeda wrote:
<SCRIPT LANGUAGE="javascript">
<!--
function seeFooter_onclick()
{
footer1.style.display = "none"
}
//-->
</SCRIPT>
You've got three problems here:
- you use the "language" attribute while you should prefer the "type"
attribute,
- you've enclosed the script part into comments, as a result it's not
even interpreted,
- you're using IE-specific object accessors, while using the standard
document.getElementById would make your script work on more platforms.

Note that it's usually recommended to externalize the script part in a
javascript include, to avoid parsing issues with the script content.
<INPUT id="seeFooter" type="checkbox" LANGUAGE="javascript"
An input element doesn't have a "language" attribute.
onclick="seeFooter_onclick()">FOOTER</INPUT>


An input element doesn't have any closing tag.
<?xml version='1.0'?>
<xsl:stylesheet
version='1.0'
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<html>
<head>
<title>Hello, World!</title>
<style type="text/css">
body { background-color:palegoldenrod }
</style>
<script type="text/javascript">
function seeFooter_onclick(){
if(document.getElementById){
with(document.getElementById("footer1"))
style.display=style.display=="none"?"":"none";
}
}
</script>
</head>
<body>
<input type="checkbox" onclick="seeFooter_onclick()" />
FOOTER
<table id="footer1" border="1" width="100%">
<xsl:for-each select="REPORT/FOOTER/FIELD">
<tr>
<td width="40%"><xsl:value-of select="KEY" /></td>
<td><xsl:value-of select="VALUE" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>

</xsl:template>
</xsl:stylesheet>
HTH,
Yep.
Jul 23 '05 #3

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

Similar topics

15
by: Mel | last post by:
if you know of dynamic expandable folder using CSS and display function, please drop me a note Yours, Mel
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...
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
2
by: Jeronimo Bertran | last post by:
A couple of questions I am having problems with converting my JavaScript to C#. I have the following code using JavaScript for the mouseover handler that works fine: <SCRIPT...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
0
AnuSumesh
by: AnuSumesh | last post by:
Hi All, I want to call RDP on Page load and it is working fine.My code is in C#. But I am unable to perform following functions 1. when i disconnected from RDP, i want to go back to...
7
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser...
6
Frinavale
by: Frinavale | last post by:
Apparently I have a lot of questions today regarding JavaScript security. I've implemented a JavaScript Object that intercepts page submits (postbacks) and then displays a UI prompting the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.