Wednesday, January 07, 2009

Full program @ UCSD

Here is my teaching schedule for this quarter:

Introduction to the Spring Framework (Winter 2009)

Java Programming I: Introduction to Java Programming (Winter 2009)

Mapping Objects to Relational Databases using Hibernate (Winter 2009)

Struts 2.0 (Winter 2009)

That's plenty and I am really excited about that line-up --

Monday, January 05, 2009

Going crazy with XSL and Xalan

Recently I spent some time transforming one XML to another with an XSD and I was going crazy!

So let's start:

Passing parameters to the XSD

In the XSD write for instance <xsl:param name="fileName"></xsl:param> to access the parameter and in Java you do xmlTransformer.getTransformer().setParameter("fileName", "test"); You then can refer to the parameter with $filename

Calling Java methods from the XSD
  1. Write a static Java method which does what you want, e.g. public static String getFileMd5Hash(String path) {...}
  2. Declare the class containing those methods in the header of the XSD as a new namespace:
    xmlns:md5="xalan://com.mycompany.myclass"
    exclude-result-prefixes="md5 xalan">
  3. Call the method with <xsl:value-of select="md5:getFileIdMd5Hash($fileName)"> $filename is accessing the filename parameter declared in the previous method -- you can also have void or use the name of a node

Labels: , ,