Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2006, 05:04 AM
Authorized User
 
Join Date: May 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default firefox/mozilla crash: javascript in XSLT

Hi
I am fairly new to XSLT, if not that new to programming.
 I hope that I will find some answers to my questions
on this forum, and that you dont mind answering newby questions.

My question to start off with, is this.
I am trying to create variables using javascript, and accessing
them in my XSLT stylesheet.
The XSLT styelsheet below works in Internet Explorer, but makes
Mozilla and Firefox crash. Why, and how can I achieve a similar effect in Mozilla and Firefox?


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
    <html>
        <head>
        <title></title>
        <link rel="stylesheet" href="basic.css"/>
        <script language="Javascript" type="text/javascript">

    var counter = 1;

     </script>

        </head>

        <body>

        <xsl:apply-templates/>


        </body>

    </html>
</xsl:template>

<xsl:template match="//heading">
<h1>
<xsl:apply-templates select="text()"/>
</h1>

 <script language="Javascript" type="text/javascript">

 document.write(counter);

 </script>

</xsl:template>

</xsl:stylesheet>

 
Old May 1st, 2006, 06:08 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I've no idea why Firefox should crash, but I think you've got the wrong end of the stick about the relationship between XSLT and Javascript.

Your XSLT is creating an HTML page, which happens to contain some Javascript. When it's finished creating the HTML page, the page can be loaded and that might cause the Javascript to execute. There's no possibility of the Javascript creating variables that the XSLT can access, because the Javascript doesn't start executing until the XSLT has finished.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 1st, 2006, 10:34 AM
Authorized User
 
Join Date: May 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No - sure - I know this.

What I am really working at is a situation where I can switch the stylesheets that are associated with an xml page. I have a .htm page with some javascript. The script creates a XSLT processor object and several Document Objects. It associates an xml file and an xslt file with a specific document object, so the information in the xml page is displayed in a particular way. A viewer can click on a button in the .htm page which via a reset() function re-assigns the stylesheet that is associated with the xml document. So the information is displayed in a different way, according to the new stylesheet that is now loaded.

This is good as far as it goes, but I would like to be able to put conditional statements in my XSLT stylesheets so that the information can be displayed in even more varieties of ways, depending what button the viewer has clicked on. i was hoping it would be possible to set a variable in the original htm page to a certain value via javascript, and to let an XSLT template show or not show information, depending on the value of the variable. I thought this might work as each time a new stylesheet loads, the button that loads it could also reset the value of the variable.

 
Old May 1st, 2006, 10:43 AM
Authorized User
 
Join Date: May 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry - I am sure the above makes little sense. You can see it at
http://www.metroweb.co.za/~bmstekker/notes.htm
http://www.metroweb.co.za/~bmstekker/notes.xml

Or the whole lot at http://www.metroweb.co.za/~bmstekker/script.zip

Ultimately I want to have the .xslt stylsheets show or hide parts of the xml document, depending on which button the viewer has clicked.

 
Old May 3rd, 2006, 04:15 PM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddiuszho Send a message via MSN to toddiuszho Send a message via Yahoo to toddiuszho
Default

Can your XSLTProcessor object accept key/value pairs for global stylesheet params before calling transformToDocument()?

If so, use JavaScript to bridge the HTML DOM and UI events to the XSLT stylesheet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
german characters not displayed in Mozilla Firefox crmpicco HTML Code Clinic 1 November 22nd, 2007 08:23 AM
Line Break Gap / Mozilla Firefox SolarEnergy BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 4 April 15th, 2007 10:20 AM
Having problems on Mozilla firefox (not able to se viral612 XSLT 0 March 12th, 2007 11:53 PM
Transform XML with XSLT in JavaScript Mozilla Spankmaster79 Javascript 3 January 18th, 2006 07:31 AM
Cr8 & Stored procedure ..Crash ..Crash swissaKM Crystal Reports 0 January 2nd, 2005 06:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.