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 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
 
Old December 15th, 2008, 12:16 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
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/
 
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.
 
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.
 
Old December 30th, 2008, 07:41 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
The Following User Says Thank You to mhkay For This Useful Post:
Kunn (December 31st, 2008)
 
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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 05:23 PM
how to pass javascript variable to xsl eruditionist XSLT 4 September 8th, 2008 08: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





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