Date function in the XSLT standard library

xiaoxiao2021-03-06  83

Using the date function date name in the XSLT standard library (DAY NAME) DAY NAME function allows us to specify a date and return the name of the date (such as Monday, Tuesday). This makes your XML document more specific for reading. Listing A is an example of the XML document we will be used herein. Listing B illustrates the usage of the DAY Name function in XSL Stylesheet.

Listing A: MyDoc.xml 2003 1 1 12 30 00 -05: 00 listing b: getday .xsl <

XSL: with-param name = "day-of-the-week" select = "$ dow" /> This code shows three different date templates in XSLT. First, we want to display the name of the date, but the value returned by the template is only one, that is, the day is the first few days in the week. This library provides us with a Calculate-Day-of-the-WEEK that calculates a weekly day.

We use this template to calculate which day the specified date is the day in the week, save this value into the XSL variable, then use the table to find the date name to get the actual Date, in this example, this final result is Wednesday.

In Listing C we will implement a Template (get-day-of-the-week-abbreviation)

Listing C:

Gotday.xml 3 Wednesday WED

The most useful function in the Date and Time Format The XSLT standard library is the date and time format function. This function allows you to modify the date and time display format as you want. It has several input parameters, such as dates, years, months, and time variables. It also has a format parameter to specify the format of the output date and time.

Listing D shows an example of using a XSL Stylesheet using a format function. In this example, we did not specify a special format, which means that the template will be displayed by default format.

Listing D: mydoc.xsl

Listing E shows the output of Stylesheet:

Listing E: MynewDoc.xml 2003-01- 01T12: 30: 00

We can customize our own format by custom format parameters. There are many parameters that can be developed in the format parameters. For example, you can specify a local time format or any arrangement date time. All documents regarding parameter settings can be accessed online.

Suppose we need to display the date and time in the following format:

Wednesday January 01, 2003

We need to use the Format-Date-Time Template as follows:

In this example,% a represents the full name of the week,% b indicates the full name of the month,% D indicates that the date is the first few days in one month,% Y represents the year ( Four digits).

more options

The XSLT standard library greatly enhances your XSL Stylesheets feature. There is also another date function in the XSLT standard library, but most of them need to be implemented via the format-date-time function. You can get these functions and parameters introduced by accessing the XSLT standard library website.

转载请注明原文地址:https://www.9cbs.com/read-95244.html

New Post(0)