XSL Tips - Using Java in XSL

William Pohlhaus' Web Site

Home > XSL Tips > Using Java in XSL


Side Links
Home
Resume
Jennifer (wedding picutes)
Seda (baby pictures)
Java
Presentation
XSL Tips
My Other Homepage (Dust Boy)
 
Using Java in XSL
This is how xalan which is the default implementation of JAXP includes java in XSL. In this example I use the java java.net.URLEncoder to in URL encode my node and well as appending the date using java.util.Date.
Here is an excellent site about this topic: http://cafeconleche.org/books/xmljava/chapters/ch17s03.html
XML
<?xml version="1.0" encoding="US-ASCII" ?>

<tests><test>m m=m</test></tests>

XSL
<?xml version="1.0" encoding="US-ASCII" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html" omit-xml-declaration="no" indent="yes" />

  <xsl:template match="tests" xmlns:date="xalan://java.util.Date" xmlns:encoder="xalan://java.net.URLEncoder"
     <xsl:value-of select="encoder:encode(string(test))"/>
     <xsl:value-of select="date:new()" />
  </xsl:template>

</xsl:stylesheet>
Result
m+m%3DmWed Aug 07 06:45:35 EDT 2002