-1

I have following VBScript in XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxsl="urn:schemas-microsoft-com:xslt"
            xmlns:user="http://www.global-health.com"
            >


<msxsl:script language="VBScript" implements-prefix="user">

<![CDATA[
  ...
Function Today()
  Today= year(Date) & "-" & LeadNumWith0(month(Date)) & "-" & LeadNumWith0(day(Date))      
End Function
]]>
  </msxsl:script>
</xsl:stylesheet>

If I use VS 2019 XSLT Debugger to exectue above stylesheet, I will get an error : 'Public Function Year(DateValue As Date) As Integer' has no type parameters and so cannot have type arguments. It works if I change function Date to Now, both Date and Now are valid VBScript function, why Date doesn't work?

Bochen Lin
  • 413
  • 4
  • 12
  • What is the reason to use the msxml2.document.3.0,? Why not to use .Net XSLT? Or even Saxon XSLT that supports XSLT 3.0 – Yitzhak Khabinsky Jul 01 '21 at 02:22
  • The XSLT files I am working on are for a Win32 application which is developed in Delphi 2007 thus I cannot use .Net XSLT. – Bochen Lin Jul 01 '21 at 02:31
  • https://stackoverflow.com/questions/417010/can-i-use-a-net-dll-in-delphi-2007-for-win32 – Yitzhak Khabinsky Jul 01 '21 at 02:35
  • The syntax you are using there is for VB.Net there is no such object in VBScript `DateTime.Now` you want the function `Now()`. See the [Official Documentation](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/0w568awd(v=vs.84)). – user692942 Jul 01 '21 at 08:29
  • @user692942 no, I did not want Now, instead, I wanted Date which is also a function supported by VBScript – Bochen Lin Jul 01 '21 at 23:38
  • @BochenLin and you weren’t using either as that is .Net syntax in the code. The only difference between the `Now()` and `Date()` functions in VBScript is one returns the date and time the other returns just the date. You can still use either if you are using functions like `Day()`, `Month()` and `Year()` to pull out various date parts. – user692942 Jul 02 '21 at 06:32
  • @user692942 The root problem is if I use VS to do the transformation, it only support Now() but not Date(), that suprised me. – Bochen Lin Jul 03 '21 at 14:49

1 Answers1

1

In VBScript, use Now to get the current date:

Today = Year(Now) & "-" & Right("0" & Month(Now), 2) & "-" & Right("0" & Day(Now), 2)
user692942
  • 16,398
  • 7
  • 76
  • 175
Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
  • Seems Now works for both VS and msxml2.document.3.0 – Bochen Lin Jul 01 '21 at 08:10
  • 1
    @BochenLin not sure why you keep referring to working in VS and MSXML, it’s VBScript plain a simple. VS us just an IDE and MSXML is a document model that allows you to use VBScript inside it. – user692942 Jul 01 '21 at 09:08
  • @user692942 Date() is also a function in VBScript, but it failed when execute the transformation by VS, so obviously, VS and msxml2 (which is the COM I am referring to) use different interpreter internally for execution. Now it looks to me that happendly Now is support both by VS and msxml2 thus I can continue use VS as the tool. – Bochen Lin Jul 01 '21 at 23:30
  • 2
    @BochenLin it failed for some other reason. There is no difference, the interpreter is the VBScript runtime, no IDE or document model is going to change that. – user692942 Jul 02 '21 at 06:28
  • @user692942 I thought that VS used VBScript runtime too, but obviously VS did not, Date is one example, I can put in other code which is VB.Net's syntax only and VS okay with that. – Bochen Lin Jul 03 '21 at 14:41