 |
| 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
|
|
|
|

August 3rd, 2005, 11:28 AM
|
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 3rd, 2005, 07:27 PM
|
|
Authorized User
|
|
Join Date: Jul 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

August 4th, 2005, 08:05 AM
|
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 4th, 2005, 08:40 AM
|
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
...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
|
|

August 4th, 2005, 09:11 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

August 4th, 2005, 09:34 AM
|
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 5th, 2005, 02:00 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

August 5th, 2005, 08:14 AM
|
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 5th, 2005, 10:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

August 5th, 2005, 10:52 AM
|
|
Banned
|
|
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm using the XMLDOM parser. Thanks.
KWilliams
|
|
 |