Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
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 Search this Thread Display Modes
  #1 (permalink)  
Old August 3rd, 2005, 11:28 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie: XSLT & Scripts

I've been back and forth between using CSS or XSLT to format my XML data. I had finally decided to use this setup for our site:
XML (pure data) > XSLT (formatting) > ASPX (transformation) > XHTML (display) > CSS (stylization & positioning)
...but my problem concerns how to show client-side scripts within XSLT.

For instance, I have this basic script that pulls today's date, and formats that date:
Code:
<%
'***Date display***
'Declare variables
Dim dtNow As DateTime, litToLongDateString As String
'Pull today's date
dtNow = DateTime.Now
'Assign today's date to string
litToLongDateString = dtNow.ToLongDateString
'Format date
'Dim litToLongDateString.Text = dtNow.ToLongDateString
%>
In a CSS generated page, I can simply call this script and it's displayed on the page. But in XSLT, this of course cannot happen. So here are my questions:
Is there a way to call client-side scripts from an XSLT page?
If so, how can I accomplish this task?
If not, how am I supposed to use XSLT as an alternative to CSS when it can't display client-side scripts?

Thanks for any & all help.

KWilliams
Reply With Quote
  #2 (permalink)  
Old August 3rd, 2005, 07:27 PM
Authorized User
 
Join Date: Jul 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not sure if I understand your question but you can both write javascript using xslt or import a js file and call the javascript functions from xslt.







Reply With Quote
  #3 (permalink)  
Old August 4th, 2005, 08:05 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:I am not sure if I understand your question but you can both write javascript using xslt or import a js file and call the javascript functions from xslt.
...but if I write a script using VB.NET syntax, can I also call that from the XSLT stylesheet? Or is it only for JavaScript?

Sorry that I wasn't more clear, but I basically want to add a link to the XSLT stylesheet to the script, and then call it from within the XSLT page. What syntax is used within XSLT for calling such a script? Thanks cleytonjordan.

KWilliams
Reply With Quote
  #4 (permalink)  
Old August 4th, 2005, 08:40 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...by the way, I found what I believe is a solution in an article by Microsoft titled "How to Include Client-Side Script Functions in an XSL Document" at http://support.microsoft.com/kb/q273793/. But thanks for your help.

KWilliams
Reply With Quote
  #5 (permalink)  
Old August 4th, 2005, 09:11 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

I don't really understand your need.
Are you trying to use script during a transformation because you don't think you can accomplish the transform using standard XSLT techniques?

Or are you trying to render HTML with script blocks that run on the browser, in which case they can be added as you would add any other literal element?


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #6 (permalink)  
Old August 4th, 2005, 09:34 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote: I don't really understand your need.
Are you trying to use script during a transformation because you don't think you can accomplish the transform using standard XSLT techniques?

Or are you trying to render HTML with script blocks that run on the browser, in which case they can be added as you would add any other literal element?
I want to know how to call that VB.NET function from the <body> tag of the XSLT stylesheet, so that it can be displayed on the XHTML page after the transformation. In a regular HTML page, I would do this:
<html><head>
<script language="vb" runat="server" src="/newsite/bgscripts/vb/currentdate.vb" />
</head>
<body>
<div id="header">
<%=(date)%>
</div>
</body>
</html>

I want to do the same thing within an XML > XSLT > ASPX > XHTML transformation. I understand that I can link the VB.NET function from within the ASPX doc itself, but I need to know how I can call that from the XSLT stylesheet (noted above). I hope that's more clear. If not, let me know.

KWilliams
Reply With Quote
  #7 (permalink)  
Old August 5th, 2005, 02:00 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 do a number of things, you could either pass the current time in as a parameter to the stylesheet or you could use VB.NET, or another language, to get the time from within the stylesheet. For this use the ms:script block. Both of these methods will produce a page that shows the time of the transform though, not the time the page is served as you have currently, which will not be the same.


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #8 (permalink)  
Old August 5th, 2005, 08:14 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe,

Thanks for the response.
You wrote:
Quote:
quote:You can do a number of things, you could either pass the current time in as a parameter to the stylesheet...

I'm actually only looking for the current date, and I wanted it formatted like this: Friday, August 05, 2005. The default date pulled into a page isn't formatted like this, which is what required my extra script. So if there's either a way to format the date within XSLT, or link an exterior VB.NET script (see below), that would be what I need.

This is the code that produces that date on an HTML or ASP.NET page:
Code:
'PULL IN TODAY'S DATE
'Declare variables
Dim dtNow As DateTime, litToLongDateString As String
'Pull today's date
dtNow = DateTime.Now
'Assign today's date to string
litToLongDateString = dtNow.ToLongDateString
'Format date
'Dim litToLongDateString.Text = dtNow.ToLongDateString
...and then I simply call <%=(litToLongDateString)%> from the HTML or ASP.NET page.

Quote:
quote:...or you could use VB.NET, or another language, to get the time from within the stylesheet. For this use the ms:script block. Both of these methods will produce a page that shows the time of the transform though, not the time the page is served as you have currently, which will not be the same.
I'm not using the MSXML parser, but I've only heard briefly about the xsl:script method. Would this method be suitable for this setup? And if so, how would I call an externally linked script's variable? I'll research this method further until I receive your reply. Thanks for your help.

KWilliams
Reply With Quote
  #9 (permalink)  
Old August 5th, 2005, 10:34 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

I can try to give an example if you tell me which parser you are using, I presumed as you were using ASP.NET that you were using the .NET parser which supports the ms:script block.
The xsl:script block does not exist, it was in a precursor to XSLT but was dropped from the final spec.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #10 (permalink)  
Old August 5th, 2005, 10:52 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm using the XMLDOM parser. Thanks.

KWilliams
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Newbie XSLT question fedehf XSLT 4 January 29th, 2008 03:09 PM
Calling external scripts from XSLT dextermagnific XSLT 2 June 25th, 2007 03:55 AM
Newbie XSLT question wasabi XSLT 2 March 8th, 2007 01:06 PM
PakageMaker & External scripts murraywj Xcode 1 May 12th, 2006 05:00 PM
Restore & Delete Scripts Walden SQL Server 2000 1 June 16th, 2003 06:10 PM



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


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