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 March 19th, 2015, 02:38 PM
Authorized User
 
Join Date: Mar 2007
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default Producing variable value with JS?

I am trying to get screen_width with JS and store it into a variable but get no success. My attempt:

PHP Code:
<xsl:variable name="screen_width">
   <
script type="text/javascript">return (screen.width);</script>
</xsl:variable> 
When I get the variable value instead of print out say "1280" (an example of a screen width) it is printing "return (screen.width);"

Could someone please point me what is my mistake?

Thanks!
 
Old March 20th, 2015, 07:47 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I am assuming you are trying to transform some XML, using XSLT, in the browser?

What you are trying to do (the way you are trying to do it) is not possible. You would need to write an extension function, which I don't think many XSLT processors in browser support.

What you will have to do is to write some JavaScript that manipulates the result AFTER XSLT has rendered to HTML.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 20th, 2015, 08:28 AM
Authorized User
 
Join Date: Mar 2007
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Sam, yes, it is a XML.CONFIG script that I will need to detect the client viewport width.

So, are you saying that there is not a straight forward way to exchange data between XML and JS?
 
Old March 20th, 2015, 10:58 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I don't know what an XML.CONFIG file is I'm afraid, or what you'd use one for.

Saxon has a version of their XSLT processor called Saxon-CE which is an in browser XSLT processor with cross browser support, and you can call out to JavaScript functions. Other than that, unless you are only targetting IE and can write msxml extension functions then no, I don't think you can do what you are after.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old March 20th, 2015, 11:00 AM
Authorized User
 
Join Date: Mar 2007
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Well, anyway, I figured it out on a way that I did NOT to do but it worked.

Since I wanted to make the main elements of the page to stretch depending on the cliente viewpart width, of course it would be too much more simple to pick the value just once and carry it into a variable. Instead I had to do something like this for EACH stretchable element on page:

<script type="text/javascript">document.getElementById('element-id-name').style.width = (screen.width-20) + "px";</script>

Unless by the fact that I had to repeat the code along the page almost 20 times it worked perfectly.

 
Old March 20th, 2015, 11:08 AM
Authorized User
 
Join Date: Mar 2007
Posts: 17
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
I don't know what an XML.CONFIG file is I'm afraid, or what you'd use one for.

Saxon has a version of their XSLT processor called Saxon-CE which is an in browser XSLT processor with cross browser support, and you can call out to JavaScript functions. Other than that, unless you are only targetting IE and can write msxml extension functions then no, I don't think you can do what you are after.
I think that 'XML.CONFIG' is a proprietary filename. Other than that it is nothing else than a XSLT script.



Anyway, I am not targeting IE in any manner... I only do stuff for other browsers and if it works at IE that's a very good luck for whose still use that M$ crap! LoL!



Good news is that I figured out how to do what I wanted (see post above). It is a bit more handwork but at the end of the day it will do what I need. More concerned here on produce results than find an elegant solution, I shamelessly confess!



Thanks for all your support Sam!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with XSLT variable into JS yankleber XSLT 10 January 22nd, 2015 07:08 AM
@include js variable smys123 JSP Basics 0 May 17th, 2011 12:17 PM
Pass a Variable from VBS to JS kriemer Javascript 7 March 8th, 2009 04:09 PM
only do HTML/ASP when JS variable = true crmpicco Javascript How-To 1 July 19th, 2005 05:06 AM
use a JS-variable/function inside a tag cybermaarten Javascript 3 January 20th, 2005 05:42 AM





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