Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 13th, 2008, 07:26 PM
Registered User
 
Join Date: Dec 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Set xsl variable using Javascript variable

Hi Guys,

I have a variable in javascript called itemID
And i want to set xsl variable using itemID.

<xsl:variable name="id">itemID</xsl:variable>

Could anyone suggest an example of how I can set xsl variable using Javascript variable.
Highly appreciated.

Kunn
Reply With Quote
  #2 (permalink)  
Old December 15th, 2008, 12:16 PM
joefawcett's Avatar
Wrox Author
Points: 9,731, Level: 42
Points: 9,731, Level: 42 Points: 9,731, Level: 42 Points: 9,731, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,068
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You need to show how you are executing hte transformation. Setting variables is implementation defined so we'll need to know what platform you're on too.
__________________
Joe
http://joe.fawcett.name/
Reply With Quote
  #3 (permalink)  
Old December 18th, 2008, 06:30 AM
Registered User
 
Join Date: Dec 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Sir,

Sorry for the late reply.
What I want to do here is very simple. I create a textbox and user will input the text into the textbox and click on the check button. And in the javascript it will go through the xml file and look through the ID that the user just type in to see if it exists.
I have put my xml code and xsl code in this post. Please have a look. Thanks

This is my xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type = "text/xsl" href = "test2.xsl"?>
<xml>
<book>
<ID>book1</ID>
<price>5.00</price>
</book>
<book>
<ID>book2</ID>
<price>10.00</price>
</book>
</xml>

==============================================

This is my xsl:

<?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="xml">
<html>
<head>
<script type = "text/javascript">
function check()
{
var itemID = document.getElementById("aID").value;
alert(itemID);
<xsl:variable name="id">itemID</xsl:variable>

// The following is what I want to do after set xsl variable with Javascript
<xsl:for-each select = "book">
<xsl:if test="ID=$id">
alert("Book ID exist");
</xsl:if>
</xsl:for-each>
}
</script>
<title> XSL Example </title>
</head>
<body>
<input type = "text" name = "aID" id = "aID" value = "" />
<input type = "button" value = "Check" onClick = "check()" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>

================================================== =======

I just want to transform it into xsl using the xml file.
Sorry I am not sure about the platform that you mention. I am using IE to run all this stuff.
Please let me know if you requires any more information.
Thanks a lot.
Reply With Quote
  #4 (permalink)  
Old December 30th, 2008, 06:23 PM
Registered User
 
Join Date: Dec 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Could anyone provides me with a solution please.
Reply With Quote
  #5 (permalink)  
Old December 30th, 2008, 07:41 PM
mhkay's Avatar
Wrox Author
Points: 17,773, Level: 58
Points: 17,773, Level: 58 Points: 17,773, Level: 58 Points: 17,773, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,839
Thanks: 0
Thanked 267 Times in 262 Posts
Default

You are confused about the relationship of your XSLT code to your Javascript code. Your XSLT code is generating an HTML page, which contains a script element, which contains Javascript code. When the transformation finishes, you have an HTML page, whose Javascript code can then be activated by user action with the mouse. The Javascript can't possibly change a variable in the XSLT because the XSLT has finished execution. What you are trying to do is something like this:

http://en.wikipedia.org/wiki/Drawing_Hands
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
Kunn (December 31st, 2008)
  #6 (permalink)  
Old December 31st, 2008, 02:43 AM
Registered User
 
Join Date: Dec 2008
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks. That ended my confusion.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 06:23 PM
how to pass javascript variable to xsl eruditionist XSLT 4 September 8th, 2008 09:37 AM
constructing node-set content to xsl:variable MrWay XSLT 3 February 28th, 2006 10:39 AM
set a asp variable with a value in Javascript crmpicco Javascript How-To 6 March 11th, 2005 11:07 AM
set a asp variable with a value in Javascript crmpicco Classic ASP Basics 3 March 10th, 2005 10:46 AM



All times are GMT -4. The time now is 09:21 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.