Topic: using javascript in a xsl stylesheet (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=10900" title="Pages that link to Topic: using javascript in a xsl stylesheet (Page 1 of 1)" rel="nofollow" >Topic: using javascript in a xsl stylesheet <span class="small">(Page 1 of 1)</span>\

 
stefanocerra
Obsessive-Compulsive (I) Inmate

From: Bologna, Italy
Insane since: Feb 2003

posted posted 02-05-2003 16:57

maybe i'm asking something idiot.. please forgive me!

I'm trying to use some javascript function in a xsl stylesheet, and it doesn't work.
Theese are the functions:

<script language="JavaScript">

<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW &#0124; &#0124; innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->

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_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible' v='hide')?'hidden':v; }
obj.visibility=v; }
}
//-->
//-->
</script>

I copied them from a html document made with dreamweaver!

And I tried to call them in the stylesheet in this way:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl utput method="html" />

<xsl:template match="/">

<head>
<title> - </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>

...

<!-- I create a layer with div tag and the name is given through a generete-id function -->

<div id="generate-id(.)" style=" visibility: visible"><b><xsl:value-of select="./numnota" /> </font><xsl:value-of

select="./testonota" /></b> </div>

<!-- then i recall the function trying to hidden the layer, referring to the same element and so the same generated id -->

<b onClick="MM_showHideLayers('generate-id(.)','','hidden')"> [<xsl:value-of select="./numnota" />]</b>

I don't know which is the way to put the javascript functions in the xsl stylesheet! I dont understand why dreamweaver is using comment tags containing the javascript functions... if I erase these tags, and use &amp; etc., the browser can use my stylesheet, but the functions don't work (Errors loading the page...)

I hope of having been clear, and that someone can help me!

thanks a lot,

Stefano


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 02-05-2003 18:04

In XSLT, anything within comment tags (<!--, --> ) is ignored. Your script is within comment tags. Those must be removed. If you want the transformed document to have comment tags, you must use <xsl:comment>...</xsl:comment>.

Secondly, the appearance of an ampersand(& in an XML language means an entity (such as <, for instance) is coming up. So all &'s in your script must be replaced with &amp;amp;. This means you'll have a lot of "if (blah &amp;amp;&amp;amp; blah)" in your script.

[edit: stupid UBB messes up character entities; turned all my &amp;amp;'s into &'s]

[This message has been edited by Slime (edited 02-05-2003).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-05-2003 18:28

umm ??

[This message has been edited by bitdamaged (edited 02-05-2003).]

stefanocerra
Obsessive-Compulsive (I) Inmate

From: Bologna, Italy
Insane since: Feb 2003

posted posted 02-05-2003 23:51

Well i have to explain... in the former example i was using the tag <script> in the head section of the html code generated by the xsl stylesheet. If i erase the comment tags i have to use the entity names &amp; and < --- and the functions don't work.

Then i tried to do something like that:

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

version="1.0">

<xsl utput method="html" />

<lxslt:script lang="JavaScript">

function MM_reloadPage(init) {
if (init==true) with (navigator) {if ((appName=="Netscape")&amp;&amp;(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW &#0124; &#0124; innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_findObj(n, d) {
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>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<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&amp;&amp;d.layers&amp;&amp;i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x &amp;&amp; document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() {
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible' v='hide')?'hidden':v; }
obj.visibility=v; }
}

</lxslt:script>

<xsl:template match="/">

<head>

etc...

But it doesn't work again!

Now... I'm not so interested in using exactly these functions! So if someone has some functions useful to show and hidden layers, and can help me... i'll be grateful. The only important thing is that i need not to name the layers in the functions' definition: i need to pass the name of the layes as a variable of the function.

Thank you guys,
Stefano

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 02-05-2003 23:59

Did you actually try the character entities? They're required, and will be parsed into what you intend the code to be. (That is, if you say "if (blah &amp;amp;&amp;amp; blah)", the parser will insert the text "if (blah && blah)" into the HTML document.

Or is the problem occuring *after* it's been put into the document (for instance, it's a javascript error)? If that's the case, then show us the produced HTML code that fails.

What is the specific error that you get?

stefanocerra
Obsessive-Compulsive (I) Inmate

From: Bologna, Italy
Insane since: Feb 2003

posted posted 02-07-2003 17:33

I used the character entities.
The browser can load the page, but when i click in the place where i activated the javascript, an error message is displayed on the status bar. (I'm using an italian version of Explorer, but the meaning is "Error while loading the page").

In this moment i'm not able to show you the html code, i'll try monday. Thank you a lot.
S.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 02-07-2003 17:38

Double-click the text "error while loading the page," and a more detailed error message should appear. It will also give you the line number in the HTML code that the error appears. You can look into the HTML code with right click -> view source to see what's on that line, and then see if you can figure out what went wrong.

If you commonly develop with JavaScript, you should also click the "Always display this when a page has errors" checkbox on the error report.

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 02-08-2003 10:20

I always use Netscape to test my code once it seems to be ready .. that way I can use the Javascript Console to see where the error really is. Explorer's error messages (even the detail ones) are abysmally bad, and the line refs have no relevance, since they only seem to point to the HTML line where the error started from ... At least NS tells you the scipt file and the line number .. it even lists the line generating the error.

Once tested in Netscape - I got to IE to see if I get any IE specific errors.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu