Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Advanced
Mar 20, 2007



Application Security Testing: An Integral Part of DevOps

Create a "Current Date" Extension Element for Xalan

This tip is just a small application that creates an extension element for the Xalan processor. The name of the new element is <today> and it can be used to access the current date. After the application code, there's a small XSL stylesheet that uses this element.

//Java code
package xslt.extension.myelement;

import java.util.Calendar;

public class MyExtension{
   public String today(org.apache.xalan.extensions.XSLProcessorContext XSLPC,
    org.apache.xalan.templates.ElemExtensionCall EEC)
    String[] luni={"January","February","March", 
    Calendar C=Calendar.getInstance();
    String luna=luni[C.get(Calendar.MONTH)];
    String data=String.valueOf(C.get(Calendar.DATE));
    String an=String.valueOf(C.get(Calendar.YEAR));
    return (data+"."+luna+"."+an);

//XSL stylesheet
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:ext="xalan://xslt.extension.myelement.MyExtension"
           <xsl:output method="html" version="4.01" encoding="ISO-8859-1"
 indent="yes" media-type="text/html" />	        
<xsl:template  match="/...">	
     <body bgcolor="#FFF2EC"> 	 			          
      <font face="arial" size="2">

Leonard Anghel
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date