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 November 10th, 2006, 03:50 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hot-Linking back to the same document ...

Dear All,

I have an XSL stylesheet which uses javascript to apply various filters and sorts. The user can select values from lists in a <FORM> and then click on 'select' to apply the filter.

Here is an example of the call to the javascript code:

<input type="button" value="Select" onClick="ApplyFilter(document.formfilt.myfilter.va lue)"/>

The call could also be a literal value: ApplyFilter('John Smith Ltd.')

However, what I would like to do now is to link the form back on itself by making hyperlinks activate the filter code.

For example, I would create hyperlinks in tables (e.g. each company) thus ...

<a href='ApplyFilter('John Smith Ltd.')'>John Smith Ltd.</a>
<a href='ApplyFilter('Peter Brown Ltd.')'>Peter Brown Ltd.</a>

Of course the list of companies would be stored in an XML file and would be declared in a template. So the syntax which I need here is a way for the stylesheet to pass the value retrieved from each particular entry in the XML to the javascript procedure ApplyFilter().

I am not sure if this is possible but I really hope it is because it would mean that my users could then click on a company name and the view would flip to display details for that company. Such a feature would dramatically increase comfort.

Anyway, I hope that someone out there can help me with this?

Regards and thanks,
Alan Searle.

Reply With Quote
  #2 (permalink)  
Old November 10th, 2006, 09:57 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

It looks to me as if the Javascript you talk about is being generated by the XSLT stylesheet as part of an HTML document. As far as the XSLT is concerned, the Javascript is just text, and you generate it in the same way as you generate any other text. Work out what HTML/Javascript you want to generate, and then write the XSLT code to do it. For example, you can write in your stylesheet:

<xsl:for-each select="company">
  <p><a href="ApplyFilter('{name}')">
     <xsl:value-of select="name"/>
  </a></p>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old November 14th, 2006, 10:08 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Super: That worked great! These links will significantly increase navigation comfort in the XSL forms!

However, I couldn't get the syntax to work exactly as I wanted and so took a rather round-about route. Here is what I arrived at in the end:

<xsl:variable name="pcredcodestore1" select="cred"/>
<td onClick="ApplyFilter('{$pcredcodestore1}');">
<xsl:value-of select="cred" />
</td>

It's OK but I have two questions which could help to improve it:

1. Is there a way for me to avoid using a variable ($pcredcodestore1) to store the value 'cred'?
2. I wanted to have the call as a hyperlink rather than an 'onClick' event but the browser returned a message of 'internet address not found' when I put the call in href syntax. Is there a way that I can specify here that it is not an internet address but a call to javascript?

Thanks very much for your help.

Regards,
Alan.

Reply With Quote
  #4 (permalink)  
Old November 14th, 2006, 10:38 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

(1) is there a way to avoid the variable? Yes, change

<xsl:variable name="pcredcodestore1" select="cred"/>
<td onClick="ApplyFilter('{$pcredcodestore1}');">

to

<td onClick="ApplyFilter('{cred}');">

(2) Is there a way that I can specify here [in href] that it is not an internet address but a call to javascript?

That's an HTML question not an XSLT question. I think most browsers allow href="javascript:......" but you'll have to look somewhere for the details.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old November 15th, 2006, 02:43 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Fantastic: Both your suggestions worked perfectly!

Thanks,
Alan.

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
Using Session...hot to do that? Shuchik Classic ASP Basics 1 August 31st, 2007 01:49 AM
Re-linking the front and back end Scripts82 Access VBA 2 February 23rd, 2006 11:26 PM
hot keys in C++ carl.dufresne@sita.aero C++ Programming 3 January 5th, 2006 01:28 AM
Hot Keys Louisa VB.NET 2002/2003 Basics 6 September 27th, 2004 09:48 AM
history.back or hitting the back button won't work lian_a Classic ASP Basics 4 July 29th, 2004 12:14 AM



All times are GMT -4. The time now is 04:17 AM.


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