首页 > 代码库 > XSLT 调用java

XSLT 调用java

XSLT调用JS  http://www.ibm.com/developerworks/cn/xml/tips/x-tipxsltjs/index.html
XSLT调用JAVA  http://unmi.cc/xslt-call-java-method

 

Java代码  
  1. package org.lvsenlin;   
  2.   
  3. import java.text.SimpleDateFormat;   
  4. import java.util.Random;   
  5.     
  6. public class XsltFunctions {   
  7.     public static int re_int(int a){   
  8.         return a;   
  9.     }   
  10.     public static int re_random(int a){   
  11.         int r=new Random().nextInt(10000);   
  12.         return r;   
  13.     }   
  14.     public static String TimeStampDate(String timestampString){       
  15.         String date = new SimpleDateFormat("yyyy-MM-dd").format(Long.parseLong(timestampString));   
  16.         return date;   
  17.     }      
  18.     public static void main(String[] args) {   
  19.         String date = TimeStampDate("1322755200000");   
  20.         System.out.println(date);   
  21.     }   
  22. }  
package org.lvsenlin;import java.text.SimpleDateFormat;import java.util.Random; public class XsltFunctions {    public static int re_int(int a){        return a;    }    public static int re_random(int a){    	int r=new Random().nextInt(10000);		return r;    }    public static String TimeStampDate(String timestampString){        	String date = new SimpleDateFormat("yyyy-MM-dd").format(Long.parseLong(timestampString));    	return date;	}       public static void main(String[] args) {    	String date = TimeStampDate("1322755200000");    	System.out.println(date);	}}

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

Xml代码  
  1. <xsl:stylesheet version="1.0"  
  2.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    
  3.     xmlns:java="org.lvsenlin"  
  4.     exclude-result-prefixes="java">  
  5.   
  6.     <xsl:template match="/">  
  7.         <msc type="form">  
  8.             <body>  
  9.                 <xsl:value-of select=‘java:XsltFunctions.TimeStampDate("1322755200000")‘ />  
  10.             </body>  
  11.         </msc>  
  12.     </xsl:template>  
  13. </xsl:stylesheet>  

XSLT 调用java