Guide
Test Your Knowledge
- Add an XSLT function.
- Specify its name as “ShowCurrentDate”.
- Specify its namespace as “Demo”.
- In the function editor, on the Settings tab, write its description.
- Save the function.
- In the Functions perspective, expand All Functions, select Demo and click Generate Documentation on the toolbar.
- Make sure the function has the description.
- Add a function call to Composite.Utils.Date.Now.
- Specify its local name as “CurrentDate”.
- Save the function.
- On the Template tab, remove the default contents between the <body> and </body> tags.
- Use the called Composite.Utils.Date.Now function’s output in the markup by referring to it by its local name “CurrentDate”.
- Save the function.
- Preview the function and make sure that the current date appears in the input and output panes.
- Add the Boolean parameter “LongDate”.
- Edit its default value.
- Add Composite.Constant.Boolean and set its value to “True”.
- Save the function.
Task: Use an Extension Function
- Add a call to the extension function Xslt.Extensions.DateFormating.
- On the Template tab, register the ‘xsl:df = "#dateExtensions"’ namespace.
- Use the ‘df: LongDateFormat’ extension function on the function call’s output in the template.
- Save the function.
- Preview the output of the function and make sure the long date appears now.
Task: Use XSLT to Switch between Two Date Formats
- Use the XSLT syntax to have two branches for the current date’s format (<xsl:choose> etc).
- Use the input parameter “LongDate” and its value (‘true’, ‘false’) to specify each branch of the current date’s format (<xsl:when test=”...”> etc).
- For the “LongDate” set to ‘true’ use the ‘df:LongDateFormat’ extension function on the “CurrentDate” function’s output
- For the “LongDate” set to ‘false’ use the ‘df:ShortDateFormat’ extension function on the “CurrentDate” function’s output.
- Save the function.
- Insert the function on a page in the Content perspective.
- Set its LongDate parameter to ‘false’.
- Preview the page and make sure that the date is displayed in short format.