XSL Transformation using Xalan and Java
Part II »»»
In this article I’ll be talking about how I used
XML, XSLT & Java to solve a problem I faced in the systems
interface module of my project. We have various clients with varied type of data
files and data streams. They send in their data and we transform those into
XML documents and files. Then there is business logic, which uses that data does some
more processing and the results are to be sent back to the same clients or different
Each carrier has its setup. Some accept XML, some only plain TEXT and some HTML.
Depending on the output needed we need to transform the given document into the
XML is used as the primary format for transmission of data among the clients
and carriers through our system.
XSLT contains the various translation formats and templates using which the
XML documents can be converted from the clients XML to the carriers XML or
HTML or Text formats.
Java programs helped in loading, parsing and creating various structures
from the XML documents and data streams. In the programs we also loaded the
XSLT files and matched the required template details and converted
the XML to the output type i.e. XML, HTML or TEXT.
The basic tools needed for the above setup to be up and running were:
- JDK 1.2 or higher from Sun,
- Xalan – Java version 1.2 or higher from Apache,
- XSLT templates developed by the programmer,
- XML Documents containing data from the clients, &
- XML / TEXT / HTML format from the carrier
- Some details about Xalan
Xalan is a joint project between Sun and Apache Foundation.
Xalan is a software program for converting XML based documents into HTML, text or other XML documents
using the XSLT and XPath specifications.
Xalan is based on the W3C recommendations for XSLT and XPath languages.
For parsing the XSLT language, it uses an XSLT processor.
Xalan has been developed in Java and C++ also. I’ll be talking specifically about
Xalan-Java version 1.2.2 in this article. In the Java version of Xalan there are
some Jar files, which can be used in our projects for transformations. A Java
program using Xalan can be a command line application, an applet or a Servlet.
Xalan uses the Xerces XML parser as its default parser, which is also from the
Apache foundation. But we can change that to use any parser that is DOM Level 2 or SAX Level 1
To learn more about Xalan:
Getting Started with Xalan
I’ll talk about Java programming and how to develop and deploy the
complete translation system in the next few articles.
Part II »»»
About the author:
Vijay Kukreja is a software developer and consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web and across heterogeneous systems.
Vijay has participated in numerous consulting projects involving Java, CORBA & XML, or a combination of the same. He frequently provides onsite Java and/or XML development at the high-tech companies located in and around Andover, MA. He has also published articles on Java Programming and JSP and Servlets in various online magazines with other consultants.
Vijay holds a Masters degree in Computer Science from the University of Pune (India) and has more than 6 years of experience in the application of computer technology to real-world problems.
The programs and names are registered trademarks of their appropriate
owners. The usage of the examples supplied by Apache and Sun are only meant
for educational and information purposes. The writer of this article & perfectxml.com does
not take any responsibility of the functionality of the above Xalan
Software. The intended use in this article is only educational and not
commercial or otherwise.