"XSLT is important for J2EE (Java 2 Platform, Enterprise Edition) developers because styling XML documents has become a server-side operation. Also, JAXP (the Java API for XML Processing), which includes support for XSLT engines, has become part of the J2EE specification (J2EE 2.6.11). In its infancy, XSLT was intended to style XML on the client; however, most applications style the XML before sending it to the client. For J2EE developers, this means that the XSLT processor will most likely run within the app server."
"As a first step, the user typically fills out an input form and sends the data with a HTTP GET or POST request to the server. The Front Controller servlet (Front Controller is a Sun J2EE pattern) examines the request and instantiates one or more helper classes. A helper class's important tasks include reading the request parameters the user sends, validating them if necessary, and storing them in a JavaBean. So, every page presented to the user corresponds to a JavaBean that serves as the model for the HTML view in the well-known Model-View-Controller (MVC) pattern."
"This article introduces a way to handle XML documents that goes beyond the standard Java APIs for manipulating XML. We'll see that in many cases XPath and XSLT provide simpler, more elegant ways of solving application problems. In some simple samples, we will compare a pure Java/XML solution with one that utilizes XPath and/or XSLT."
"Stylesheets are defined by a set of XSL commands. They make up valid XML documents. Stylesheets use pattern matching to locate elements and attributes. There are also expressions that can be used to call extensions -- either Java objects or JavaScript. Let's look at some XSL commands."
"In this article, I lay a foundation for a simple framework I successfully employed to build truly adaptive systems. It is based upon dynamic source code generation from a class's metadata maintained in a data dictionary. In the process, you'll get a refresher on JDBC (Java Database Connectivity) and JSPs (JavaServer Pages), and you'll also learn to generate source code with one of today's most fascinating XML-related technologies, XSLT (Extensible Stylesheet Language for Transformations)."
"In this article, we introduce Model 2X, a scheme that further enhances Struts. By replacing JSPs (JavaServer Pages) with XML and XSLT (Extensible Stylesheet Language Transformations), Model 2X offers an even better approach to separating logic and presentation. We start with an introduction to Model 1 and Model 2, describe how Struts implements MVC, and finally show how XML and XSLT can be used to improve the existing models."
"This chapter is devoted to Java and XSLT programming techniques that work for both standalone applications as well as servlets, with a particular emphasis on Sun's Java API for XML Processing (JAXP) API. In Chapter 6, we will apply these techniques to servlets, taking into account issues such as concurrency, deployment, and performance."
"This article explains the basic patterns and programming techniques commonly used when XSL Transformations (XSLT), Java Servlets, and XML are combined to create sophisticated web applications. The types of applications that benefit from this approach include"
"In summary, this architecture enables development to clearly separate data from the presentation. This separation leads to successful deployment of systems that require intensive co-branding because presentations can be easily added or modified without changing the underlying business layer. Moreover, by separating the data from the view in a clean manner, Java developers and HTML developers have a clearer view of their responsibilities within the software development lifecycle. Also, Skin eMax aids in soothing the common headache developers have with maintaining smattered Java code in the presentation tier."
"Servlet Filter Code and Job Description The conversion job as shown in Figure 1 will be done by a Servlet Filter. Servlet Filters have been a standard part of Servlet API since version 2.3. They allow modifying HTTP response and can serve many different purposes, including enforcing security or access restrictions of the application, caching the application content, etc. In our example, however, we'll use servlet filters to process applications of the XSLT style sheet to the XML data passed from the JSP. My example has been partially borrowed from Sun Microsystems' reference to servlet filters implementation at http://java.sun.com/products/servlet/Filters.html, however, a few modifications were made to the code in Listing 2 in order to fit into our application. For instance, I've added the code to determine the content type based on the "user-agent" header (containing client information, such as browser type) and to determine the appropriate XSLT style sheet based on the provided request URI."
"Due to the growing importance to both application and Web developers of XML and the related XSL technology, the effective use of XSL transformations cannot be ignored. Thus, it is increasingly important to learn how to program in the declarative fashion. This means becoming intimately familiar with recursion, both its basic usage and the methods for using it effectively and efficiently for the problems at hand."
"Many processors currently use a DOM tree as the internal document representation. For these processors, passing in a DOM tree is the best option because the processor can use that structure immediately, without any internal conversion. Converting your JDOM Document to a stream (using XMLOutputter) would waste time, as that stream is just going to be converted back into a DOM tree. So always try to find the shortest path between JDOM and the processor's internal representation. If you need to feed the processor a DOM tree, use JDOM's DOMOutputter, and if you need to feed the processor SAX, use SAXOutputter. In either case, the key is connecting the correct output format for your JDOM Document with the best solution for input to your XSLT processor."
"The Extensible Stylesheet Language (XSL) specification describes powerful tools to accomplish the required transformation of XML data (see Figure 1). XSL consists of the XSL Transformations (XSLT) language for transformation, and Formatting Objects (FO), a vocabulary for describing the layout of documents. XSLT uses the XML Path Language (XPath), a separate specification that describes a means of addressing XML documents and defining simple queries. The XSLT 1.0 and XPath 1.0 specifications are complete, having become W3C recommendations on November 16, 1999. The XSL 1.0 specification (which also describes FO) is expected to reach W3C recommended status soon. (See Resources for more information on the latest versions of XSLT, XPath, and XSL from the W3C.)"
"This article assumes that the reader has a general knowledge of JSP, servlets, HTML, XML, and XSLT. In this article, I will introduce a solution for the internationlization of Web content using XSLT style sheets and an XML Dictionary."
"The examples in this article use the Java-based Saxon XSLT 2.0 processor. Saxon implements the XSLT 2.0 specification (its author, Michael Kay, was the editor of the XSLT 2.0 spec), including custom collations. To use a custom collation with Saxon, you specify the name of the Java class that implements the collation function."
"The most common techniques for manipulating XML documents are DOM, SAX, and XSLT. These techniques have a distressing lack of unifying principles among them. Everything you might want to do with XML is available in one of the major approaches, but when what you want to do crosses the boundaries of what each technique does best, it is far from clear how to approach a problem. You are likely to wind up with a hodge-podge application in which various smaller transformations are chained together with heterogeneous techniques and tools."
"The automated generation of code, when applied correctly, can be a powerful engineering technique. This tutorial provides a basic introduction to code generation concepts, and in particular introduces XSLT as a code generation tool. The tutorial also discusses the limitations of XSLT when generating code, and demonstrates how to compensate for some of these issues using a flexible framework built with open source tools, such as Ant and Jalopy. This simple but powerful framework can be applied to the generation of many different types of code."
"In this section, I will compare two stylesheets. The first one is a typical XSLT stylesheet; the second is a rewriting that exposes the depth-first walk. While you would not want to adopt this coding style, it helps explain how the processor works."
"XSLT 2.0, the latest specification released by the W3C, is a language for transforming XML documents. It includes numerous new features, with some specifically designed to address shortcomings in XSLT 1.0. In this collection of articles, you'll get a high level overview and an in-depth look at XSLT 2.0 from the point of view of an XSLT 1.0 user who wants to fix old problems, learn new techniques, and discover what to look out for. Examples derived from common applications and practical suggestions are provided if you wish to upgrade. To help you begin to use XSLT 2.0, migration techniques will be provided. Check the library for additional articles in this Planning to upgrade series."
"In this lesson, I will explain default XSLT behavior, and will show you how to write Java code that mimics that behavior. The resulting Java code serves as a skeleton for more advanced transformation programs."
"Before I describe ways that XSL and XML could help us solve certain problems, it would be desirable to define what problems we have. Conditional compilation is a rather extensive concept. In the context of this article, with the meaning "conditional compilation," we will have an opportunity to compile a project at once with some different variants and/or versions, depending on a used key-argument. To understand what we are talking about, C/C++ programmers can recollect, for example, instructions of #define and #ifdef preprocessors. Such directives exist in many languages, but not in Java."
"Richard has participated in numerous consulting projects, and he frequently provides onsite training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Programming Tutorials, which has gained a worldwide following among experienced and aspiring programmers. He has also published articles in JavaPro magazine."
"I find that XSL makes parallel development easier. Once the XML data format has been agreed upon, a presentation developer can completely build the XSL view markup through an XML IDE without even needing a servlet container to construct and test the code. A XSL developer does not have to know Java. It is very easy to integrate the view with the rest of the application when ready. With a JSP view, this could still be accomplished by creating a "stub" object to stand in for the model, but it doesn't lend itself as naturally to this approach."
"In my opinion, it is difficult to exaggerate the opportunities and advantages that XML/XSL technologies provide to developers. Also, you can imagine a situation when it is necessary for you to deploy the same document on different devices (the personal computer, mobile phone, a handheld computer, and so forth); in that case, you can store the document as XML and apply to it different XSL schemes. And, it is worth mentioning that the division of the data on various files allows us to optimize working hours and correctly divide duties of all programmers and designers (actually, with what we also have begun in this article)."
"Together, the first two parts cover 70% of XSLT coding needs and you write many fine stylesheets using only these techniques. This month, we will cover more advanced techniques that simplify XSLT coding."
"To conclude this section on XPaths, let's look at predicates. Predicates allow you to specify conditions that must apply to an element. The predicate appears between square brackets, [ and ], immediately after the element on which the condition applies."
"Hopefully, you've seen in this article that it is not only possible, but indeed quite practical, to put the new JSF standard to use with a display technology other than JSF, and have gained some idea how that might be done. A number of open-source projects are already underway to provide implementations of the JSF standard, including MyFaces, Smile, and the Keel meta-framework, from which the above examples were drawn."
"To avoid problems, you should realize that there are two different coding styles in XSLT: the declarative flavor that uses templates and predicates, and the procedural flavor with loops and tests. XSLT, as a language, is biased towards the first and this bias should be reflected in your style sheets."
"This is the first article in a new series introducing XSLT. XSLT is an acronym for XML Stylesheet Language Transformations, but I believe the W3C should change it into XML Scripting Language."
"XSLT is a useful addition to the Java developer toolbox, but many complain that is too limited. In my experience, I find that XSLT provides 70% to 95% of what I need, and I have to complement that with Java coding. This article demonstrates one solution to enhancing XSLT with Java."
"As an example of an advantage provided by XSLT, if it is possible to perform the required transformation using XSLT, that approach will probably require you to write less code than would be required to perform the same transformation by writing a Java program from scratch. However, I will show that once you have a library of Java methods that emulate XSLT elements, it is no more difficult to write a Java program to transform an XML document than it is to write an XSL stylesheet to transform the same document."