Jump to content
kwilliams

XSLT and JavaScript Variable

Recommended Posts

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

//Generic variablesvar subject = "?Subject=Website Comment/Question";var mailto = "mailto:";var at = "@";var url = "mysite.com";//User-specific variablesvar 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:

<?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:

<?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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...