Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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
  #1 (permalink)  
Old June 21st, 2007, 03:55 PM
Authorized User
Points: 101, Level: 2
Points: 101, Level: 2 Points: 101, Level: 2 Points: 101, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default calling template with javascript

I need an onclick function to call an xsl template and am having trouble doing so

<script type="text/javascript">
function load()
{
  <xsl:call-template name="thename" />
}
</script>

<a href="#" onclick="load()">load it</a>


the above code is an example of what I have on one particular template in an xsl file....I need the onclick event to load the other template, also on the same xsl file.

any suggestions
  #2 (permalink)  
Old June 21st, 2007, 05:17 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can't put an XSLT instruction in the middle of your Javascript code any more than you can put a Javascript instruction in the middle of a C program.

What you can do is to invoke a stylesheet transformation using the API provided by your XSLT processor. This starts the XSLT processing at the top level - it must supply an input document to be processed, and the stylesheet produces an output document which the Javascript code can then manipulate (typically by displaying it).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old November 21st, 2007, 05:35 PM
Registered User
 
Join Date: Nov 2007
Location: Halifax, , Canada.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm new to XSLT (Like most people here it seems) but I'm soaking up as much info as I can and this forum has been excellent.

When I started out, this was also probably my original plan of action as well.

I now understand that (correct me if I'm wrong) that if the XML is transformed via the XSL stylesheet on loading in the browser, that and javascript changes will not affect the output unless the page is reloaded with new templates to apply. And that call-template and apply-template are processed during (and only during) transformation.

That being said, is there a way to take a global javascript variable and make it equal in value to a global XSL parameter so that the user can input a value and the transformation will be loaded into an iframe?

(I thought that asking a straightforward question first might be smarter than pasting my huge pages of code and asking "WHY ISN'T THIS WORKING THE WAY I WANT IT TO?!"

Thanks in advance.

  #4 (permalink)  
Old November 22nd, 2007, 04:13 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can't do what you want via a transform kicked off via an xsl-stylesheet processing instruction. The standard way to do it is to have some script in an HTML page that reads the location.search and then invokes the transformation after setting the necessary parameter.

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
template calling kgoldvas XSLT 1 August 1st, 2007 10:20 AM
template calling kgoldvas XSLT 1 July 10th, 2007 07:16 AM
CALLING A TEMPLATE WITHIN JAVA SCRIPT SOMANATHAN10 XSLT 6 February 14th, 2007 02:10 AM
calling template from a href bergs77 XSLT 4 January 9th, 2006 01:11 PM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM





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