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 April 21st, 2008, 11:10 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT and JavaScript Variable

I have an XSLT page that pulls a variable from a JavaScript document. This is what the code looks like:

JavaScript
Code:
//Generic variables
var subject = "?Subject=Website#160;Comment/Question";
var mailto = "mailto:";
var at = "@";
var url = "mysite.com";

//User-specific variables
var strIT_webmaster_url = "webmaster";
var strITEmail_webmaster_url = "<a href=" + mailto + strIT_webmaster_url + at + url + subject + ">" + strIT_webmaster_url + at + url + "<\/a>";
XSLT #1:
Code:
<?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" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        Email: <script language="javascript" type="text/javascript">document.write(strITEmail_webmaster_url);</script>
    </xsl:template>
</xsl:stylesheet>
This static version works great, but I'm now wanting to pull the JS variable by using a XSLT variable is instead of the static value. This is what that code looks like:

XSLT #2:
Code:
<?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" encoding="UTF-8" indent="yes"/>
<xsl:variable name="email_webmaster">strITEmail_webmaster_url</xsl:variable>
    <xsl:template match="/">
        Email: <script language="javascript" type="text/javascript">document.write(<xsl:value-of select="$email_webmaster" />);</script>
    </xsl:template>
</xsl:stylesheet>
Although the source code of each looks exactly the same, the result of the 2nd set of code produces an "undefined" value. Is this happening because of the order in which the data is processed, or for some other reason? I'd appreciate any input.

KWilliams
 
Old April 21st, 2008, 11:27 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is no root element as a result of XSLT #1 or XSLT #2 !?!

 
Old April 21st, 2008, 11:41 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The XML document has nothing to do with my problem at this point, as I'm simply trying to pull a JS variable into the XSLT.

But for some reason, it is working now, so I'm good. Thanks.

KWilliams
 
Old April 21st, 2008, 11:53 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Be aware that document.write in HTML documents generated as the result of an XSLT transformation does not work with Firefox/Mozilla:
http://developer.mozilla.org/en/docs...ument.write.3F

--
  Martin Honnen
  Microsoft MVP - XML
 
Old April 21st, 2008, 11:56 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm currently testing it in Firefox, and it's working fine. And I just tested it in IE7 and IE6 without a problem.

KWilliams
 
Old April 21st, 2008, 12:05 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Are you doing the XSLT tranformation with Firefox itself? Then I am astonished if that works, I get all sorts of problems like the browser hanging or crashing.

--
  Martin Honnen
  Microsoft MVP - XML





Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript functions and xslt 1.0 variable mlohokare XSLT 18 December 3rd, 2008 02:22 AM
assign XSLT variable to a wml variable arunagottimukkala XSLT 2 October 19th, 2007 05:15 AM
storing Javascript variable to ASP variable rupen Classic ASP Basics 5 April 10th, 2007 07:06 AM
Using variable in XSLT -Need help !!! nobitavn94 XSLT 3 October 16th, 2006 10:32 AM
assign javascript variable to asp variable manjunath_c_k Classic ASP Basics 1 September 14th, 2006 07:35 AM





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