3 ways of transform XML with XSLT

XSLT (Extensible Stylesheet Language Transformation) is a XML-based stylesheet that used for transform XML from one format to another format. It generate new XML without alter the exisitng source XML.

To transform XML with XSLT, a XSLT proccessor is required. It can be develop based on API such as Apache Xalan.

But if you just want to transform a few XML, it is overkill to write a program for it. So here are a few way:

1) Most browsers have built-in support for XSLT. But it required the source XML to include a reference to the XSL with this:

<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>

2) Use some XML editor such as XML Copy Editor to perfrom the transformation. This is easy but it cant be automated.

3) Use command line tool to perform the transformation. By doing this, you can automate the transformation by include it in your shell script or batch script. In Linux, xsltproc can be used:

xsltproc -o output.xml stlyesheet.xsl input.xml

In Windows, you may use Xalan-Java command line utility. The command will be something like this:
java org.apache.xalan.xslt.Process -IN foo.xml -XSL foo.xsl -OUT foo.out

For the fans of Apache Ant, you may use the XSLT task which is one of the core task in Apache Ant.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply