XSLT - Raise to power

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" encoding="UTF-8" />
  <!-- Usage example: Calculate 10^5-->
  <xsl:template match="*">
    <xsl:param name="PowResult">
      <xsl:call-template name="Pow">
        <xsl:with-param name="Base" select="10"/>
        <xsl:with-param name="Exponent" select="5"/>
        <xsl:with-param name="Result" select="1"/><!-- Always set to 1 when Pow() function is used. -->

XSLT - Change letters to upper or lower cases

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

XSLT - Custom Functions

Custom XSL functions


XSLT reference

Useful identity templates

String funciton string-length()

Output xml entities as is

<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>

Handling CDATA XSL can't copy CDATA section as CDATA section. http://sources.redhat.com/ml/xsl-list/2001-05/msg00980.html

XPath's axes http://www.w3schools.com/XPath/xpath_axes.asp

Useful XPath samples  

TestNG - Testing private methods

Sometimes you need to test the private method of a class. I use reflection to access the private method. Here are the codes:

 * Class with a private method that you want to test.
 * @author Xuan Ngo
public class ClassExample
  private String privateFoo(int a, String b)
    return a+b;
 * Here is the code showing how to access the private method
 *  using reflection.
 * @author Xuan Ngo
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

SQL - Hibernate

In Eclipse, include the following JARs:

  • hibernate-distribution-3.3.2.GA/hibernate3.jar
  • hibernate-distribution-3.3.2.GA/required/antlr-2.7.6.jar
  • hibernate-distribution-3.3.2.GA/required/commons-collections-3.1.jar
  • hibernate-distribution-3.3.2.GA/required/dom4j-1.6.1.jar
  • hibernate-distribution-3.3.2.GA/required/javassist-3.9.0.GA.jar
  • hibernate-distribution-3.3.2.GA/required/jta-1.1.jar
  • hibernate-distribution-3.3.2.GA/required/slf4j-api-1.5.8.jar



Create a table
--Create a table called t1 which has 2 columns, col1 and col2. 
--col1 is defined to allow only 1 characters and col2 is defined to allow integer.
CREATE TABLE t1( col1 CHAR(1), col2 INT);
Insert data in table
INSERT INTO t1 VALUES('A', 123); -- Insert 'A' and 123 into table t1.
INSERT INTO t1 VALUES('Z', 23 ); -- Insert 'Z' and 23 into table t1.
INSERT INTO t1 VALUES('B', 23 ); -- Insert 'Z' and 23 into table t1.


# Resize image
convert -resize 50% -quality 80 input.jpg output.jpg
# Convert color to gray

Debian - Mount Hot-pluggable devices(SD cards, USB)

  1. In the shell, run fdisk -l and note all the devices listed.
  2. Plug in your device and then re-run fdisk -l. You should see your newly added device appear in the list.
  3. Create a directory for your device.


Debian is 1 of the oldest free Linux distribution that still exist today. It was first released by Ian Murdock in 1993. It is known to be very stable. As a result, people tend to use it when they are building production servers.

Source.lst generator: http://debgen.simplylinux.ch/generate.php


Subscribe to OpenWritings.net RSS