|By Frank Neugebauer||
|March 28, 2003 12:00 AM EST||
The Extensible Stylesheet Language (XSL) W3C recommendation was created as a means to display XML data. The recommendation includes a transformation language (XSLT) and formatting object (or output format) language (XSL-FO), which together provide the XSL stylesheet developer with the tools necessary to present XML.
The XSL-FO language is like HTML on steroids, because it allows not only cascading stylesheet (CSS)-type functionality, but also pagination and page layout, which are not available using HTML alone (at least not to as great a degree as with XSL-FO). However, such robustness comes at a cost; the language is very (very) verbose, which makes writing XSL-FO XSL stylesheets very difficult; thus, XSL-FO stylesheets are supposed to be produced as the result of an XSL transformation. But someone has to write the XSL stylesheet that transforms the XML into XSL-FO, and that's where this article can help.
The purpose of this article is to show you, the XSL stylesheet developer, how to make XSL-FO XSL stylesheets that are flexible and reusable. In other words, I'm going to show you how to make modularized XSL-FO XSL stylesheets.
Many of the key concepts presented in this article are not XSL-FO specific and can be leveraged to write any kind of XSL stylesheet. However, I concentrated on XSL-FO XSL stylesheets because their verbosity highlights the need for modularization more than most stylesheets.
I'm assuming a working knowledge of both XSLT and XSL-FO. For an introduction, you can refer to many resources on the Internet, including my article in the January 2002 edition of XML-Journal.
Overview of the Solution
Although this modularization solution is very flexible, it is also very simple and uses the XSL <xsl:import> and <xsl:attribute-set> elements, along with the xsl:use-attribute-sets attribute. When used properly, these elements and this attribute not only allow you to externalize the way an XML document is transformed into an XSL-FO document (<xsl:import>), but also the look-and-feel of the eventual FO document (<xsl:attribute-set>, xsl:use-attribute-sets). Figure 1 depicts all the pieces of these concepts.
From a high level, the XSLT engine reads in an XML document and XSL stylesheet (nothing new there). The main stylesheet, the one that is read by the XSLT engine, then uses <xsl:import> to use two additional stylesheets - one for the layout of the XSL-FO document and another for the "look-and-feel." The layout document then uses the use-attribute-sets attribute to get the "look-and-feel" (i.e., element attribution information) data from the "look-and-feel" XSL stylesheet, which is implemented as a series of <xsl:attribute-set> elements.
With the layout and look-and-feel externalized and separated into different stylesheets, the stylesheet writer can easily exchange both/either the layout and/or look-and-feel of the XSL-FO document information. If the XSL-FO document has such flexibility, it follows that the layout and look-and-feel of the eventual output document, a PDF file for example, has equal flexibility.
A Presentation Example
The example I'm going to present is a good case for the advantages of using a modular design in XSL. In presentation graphics (e.g., Microsoft PowerPoint), there are templates that can change the layout of pages and the color/graphics scheme of your presentation. I am going to replicate, to some degree, that same kind of functionality using XSL. If you use the ideas in this example, you can impress your friends by creating PDF presentations that are cross-platform with data separated from the presentation (which implies that the same data could potentially be used in entirely different formats).
The XML file
The data for the sample is represented in a simple XML file, named presentation.xml, that depicts the idea of a presentation with pages containing concepts (such a format is probably a little too coupled to the presentation, but it'll work). The root element of the document is "Presentation," with descriptive child elements called "Title," "Author," "Date," and "CorporateLogo," and a series of "Page" elements that take the following form:
The "style" attribute is referred to in the layout stylesheet to create the proper text layout in the presentation (e.g, PDF) output. The example is bullet, but you could extend the idea to be graphic, column, bullet-graphic, or any other style you require. You'll see shortly how the value of this attribute is used.
The position element allows you to put the "Page" elements in any order within the XML document and still have them laid out the way you want in the final output. Like the "style" attribute, the "Position" element is used by the layout stylesheet.
The main XSL stylesheet
Ultimately, the XSLT engine requires the name of a stylesheet to be processed. In this example, that file is called main.xsl and is very simple since its main purpose is to point to the correct layout and look-and-feel stylesheet. Listing 1 shows the contents of that stylesheet, minus the XML declaration and <xsl:stylesheet> element.
Within Listing 1, the <xsl:import> elements point to the layout and look-and-feel stylesheet, respectively. To change the template, you simply create a new layout and/or look-and-feel stylesheet and change the value of the import.
The other interesting point of the main.xsl stylesheet is simply that it creates the <fo:root> element and uses the <xsl:apply-templates> to transfer processing to other templates (which are defined in the plainPageLayout.xsl stylesheet).
The lookandfeel.xsl stylesheet contains a number of <xsl:attribute-set> definitions, which can be referenced using the xsl:use-attribute-sets property with an FO element. The contents of each <xsl:attribute-set> are the equivalent of attributes on XSL elements.
Take, for instance, a relatively simple <fo:simple-page-master> element, which defines a template for a page.
You can externalize all the attributes of the <fo:simple-page-master> element into the lookandfeel.xsl file by defining an <xsl:attribute-set> element as follows:
Then, you can refer to the attribute set within the <fo:simple-page-master> by using the "xsl:use-attribute-sets" attribute, such as:
Not only is the syntax easier to read, but the attributes values themselves are now externalized from the layout in what's essentially the FO equivalent of an external CSS.
In XSL-FO, layout is a matter of setting up page definitions and their contents. In my example, I use the page layout XSL document, named plainPageLayout.xsl, to perform the template matching on the XML document contents. I did this because the layout is responsible for understanding the output document, something that requires knowledge of the XML input, since the data from the latter becomes part of the former.
The plainPageLayout.xsl document itself looks like most XSL-FO stylesheets. However, instead of very long attribute listings (for look-and-feel type attributes), there are several xsl:use-attribute-sets attributes.
In terms of XSLT, plainPageLayout. xsl contains three templates: one each to process the "Presentation," "Page," and "Concept" elements, respectively. That presentation template creates the basic layout of the resulting XSL-FO document and then creates the title page, using data from the XML document. Throughout this stylesheet, xsl:use-attribute-sets attributes are used within <fo> elements to retrieve attributes from lookandfeel.xsl.
The Page template actually processes Page elements by style. That is, the
element will catch the "bullet" style pages only. Within the template, the non-title pages are set up with a title and two blank lines, after which the "Concept" elements are selected within a <xsl:apply templates select="Concept"/> statement. Finally, the "Concept" template processes each "Concept," creating an XSL-FO list with bullets.
As a side note, the stylesheet can be made even more modularized if you were to externalize your "Page" and/or "Concept" templates. Doing so would let you use the "bullet" style across different layout XSL documents. I did not do so for the sake of simplicity.
Listing 2 shows the entire contents of plainPageLayout.xsl. Within Listing 2, notice the comment that reads "<!-- Shows how to override attributes. -->." What I'm showing at that point in the stylesheet is that even if an XSL-FO element uses an attribute set, you can still override and/or amend the attribute set within the element itself, much in the same way you can override/add to an HTML element if a CSS is defined - further evidence of the CSS-like nature of attribute sets.
I believe that the proof of any technology is in the pudding. When you run presentation.xml and main.xsl through an FO processor (I used FOP 0.20.3), you will end up with a three-page PDF (if you choose the PDF output option within FOP). Figures 2 and 3 show the first two pages. Page 3 is just like page 2 but contains different concepts (refer to presentation.xml).
Figure 2 shows not only the main "Presentation" element (and the relevant non-page children of "Presentation"), but it also shows some of the XSL-FO design I created. For instance, the logo and yellow background color. The color and font characteristics are externalized within lookandfeel.xsl, of course.
Figure 3 uses the same basic layout characteristics of the title page, but also contains the list of concepts. Every "Page" that uses the "bullet" style will be rendered just as Figure 3 (refer to the third page of presentation.pdf if you download the source code, available at www.sys-con.com/xml/sourcec.cfm).
XSL-FO XSL stylesheets are long and difficult to read and write. Furthermore, it's not easy to change layout and look-and-feel without additional modularization. Using the XSL <xsl:import> and <xsl:attribute-sets> elements along with the xsl:use-attribute-sets attribute can go a very long way toward making such modularization a reality.
"We have seen the evolution of WebRTC right from the starting point to what it has become today, that people are using in real applications," noted Dr. Natasha Tamaskar, Vice President and Head of Cloud and Mobile Strategy and Ecosystem at GENBAND, in this SYS-CON.tv interview at WebRTC Summit, held June 9-11, 2015, at the Javits Center in New York City.
Jul. 7, 2015 05:15 PM EDT Reads: 310
SYS-CON Events announced today that ProfitBricks, the provider of painless cloud infrastructure, will exhibit at SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. ProfitBricks is the IaaS provider that offers a painless cloud experience for all IT users, with no learning curve. ProfitBricks boasts flexible cloud servers and networking, an integrated Data Center Designer tool for visual control over the cloud and the best price/performance value available. ProfitBricks was named one of the coolest Clo...
Jul. 7, 2015 05:00 PM EDT Reads: 1,514
The 4th International Internet of @ThingsExpo, co-located with the 17th International Cloud Expo - to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA - announces that its Call for Papers is open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than
Jul. 7, 2015 05:00 PM EDT Reads: 1,175
17th Cloud Expo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Meanwhile, 94% of enterprises are using some form of XaaS – software, platform, and infrastructure as a service.
Jul. 7, 2015 04:00 PM EDT Reads: 775
"In the IoT space we are helping customers, mostly enterprises and industry verticals where time-to-value is critical, and we help them with the ability to do faster insights and actions using our platform so they can transform their business operations," explained Venkat Eswara, VP of Marketing at Vitria, in this SYS-CON.tv interview at @ThingsExpo, held June 9-11, 2015, at the Javits Center in New York City.
Jul. 7, 2015 03:45 PM EDT Reads: 472
Discussions about cloud computing are evolving into discussions about enterprise IT in general. As enterprises increasingly migrate toward their own unique clouds, new issues such as the use of containers and microservices emerge to keep things interesting. In this Power Panel at 16th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the state of cloud computing today, and what enterprise IT professionals need to know about how the latest topics and trends affect their organization.
Jul. 7, 2015 03:30 PM EDT Reads: 646
WebRTC converts the entire network into a ubiquitous communications cloud thereby connecting anytime, anywhere through any point. In his session at WebRTC Summit,, Mark Castleman, EIR at Bell Labs and Head of Future X Labs, will discuss how the transformational nature of communications is achieved through the democratizing force of WebRTC. WebRTC is doing for voice what HTML did for web content.
Jul. 7, 2015 03:30 PM EDT Reads: 648
To many people, IoT is a buzzword whose value is not understood. Many people think IoT is all about wearables and home automation. In his session at @ThingsExpo, Mike Kavis, Vice President & Principal Cloud Architect at Cloud Technology Partners, discussed some incredible game-changing use cases and how they are transforming industries like agriculture, manufacturing, health care, and smart cities. He will discuss cool technologies like smart dust, robotics, smart labels, and much more. Prepare to be blown away with a glimpse of the future.
Jul. 7, 2015 02:15 PM EDT Reads: 887
Connected things, systems and people can provide information to other things, systems and people and initiate actions for each other that result in new service possibilities. By taking a look at the impact of Internet of Things when it transitions to a highly connected services marketplace we can understand how connecting the right “things” and leveraging the right partners can provide enormous impact to your business’ growth and success. In her general session at @ThingsExpo, Esmeralda Swartz, VP, Marketing Enterprise and Cloud at Ericsson, discussed how this exciting emergence of layers of...
Jul. 7, 2015 12:45 PM EDT Reads: 1,412
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Jul. 7, 2015 12:30 PM EDT Reads: 792
The 5th International DevOps Summit, co-located with 17th International Cloud Expo – being held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits, DevOps is corr...
Jul. 7, 2015 12:15 PM EDT Reads: 888
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal an...
Jul. 7, 2015 12:00 PM EDT Reads: 857
The Internet of Things is not only adding billions of sensors and billions of terabytes to the Internet. It is also forcing a fundamental change in the way we envision Information Technology. For the first time, more data is being created by devices at the edge of the Internet rather than from centralized systems. What does this mean for today's IT professional? In this Power Panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists addressed this very serious issue of profound change in the industry.
Jul. 7, 2015 12:00 PM EDT Reads: 742
SYS-CON Events announced today that kintone has been named “Bronze Sponsor” of SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. kintone promotes cloud-based workgroup productivity, transparency and profitability with a seamless collaboration space, build your own business application (BYOA) platform, and workflow automation system.
Jul. 7, 2015 12:00 PM EDT Reads: 1,551
Buzzword alert: Microservices and IoT at a DevOps conference? What could possibly go wrong? In this Power Panel at DevOps Summit, moderated by Jason Bloomberg, the leading expert on architecting agility for the enterprise and president of Intellyx, panelists peeled away the buzz and discuss the important architectural principles behind implementing IoT solutions for the enterprise. As remote IoT devices and sensors become increasingly intelligent, they become part of our distributed cloud environment, and we must architect and code accordingly. At the very least, you'll have no problem fillin...
Jul. 7, 2015 11:45 AM EDT Reads: 1,945
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at @ThingsExpo, James Kirkland, Red Hat's Chief Architect for the Internet of Things and Intelligent Systems, described how to revolutionize your archit...
Jul. 7, 2015 11:30 AM EDT Reads: 809
SYS-CON Events announced today that Secure Infrastructure & Services will exhibit at SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Secure Infrastructure & Services (SIAS) is a managed services provider of cloud computing solutions for the IBM Power Systems market. The company helps mid-market firms built on IBM hardware platforms to deploy new levels of reliable and cost-effective computing and high availability solutions, leveraging the cloud and the benefits of Infrastructure-as-a-Service (IaaS...
Jul. 7, 2015 11:00 AM EDT Reads: 908
In his General Session at 16th Cloud Expo, David Shacochis, host of The Hybrid IT Files podcast and Vice President at CenturyLink, investigated three key trends of the “gigabit economy" though the story of a Fortune 500 communications company in transformation. Narrating how multi-modal hybrid IT, service automation, and agile delivery all intersect, he will cover the role of storytelling and empathy in achieving strategic alignment between the enterprise and its information technology.
Jul. 7, 2015 11:00 AM EDT Reads: 1,716
SYS-CON Events announced today that Dyn, the worldwide leader in Internet Performance, will exhibit at SYS-CON's 17th International Cloud Expo®, which will take place on November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Dyn is a cloud-based Internet Performance company. Dyn helps companies monitor, control, and optimize online infrastructure for an exceptional end-user experience. Through a world-class network and unrivaled, objective intelligence into Internet conditions, Dyn ensures traffic gets delivered faster, safer, and more reliably than ever.
Jul. 7, 2015 10:30 AM EDT Reads: 1,591
SYS-CON Events announced today that CommVault has been named “Bronze Sponsor” of SYS-CON's 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. A singular vision – a belief in a better way to address current and future data management needs – guides CommVault in the development of Singular Information Management® solutions for high-performance data protection, universal availability and simplified management of data on complex storage networks. CommVault's exclusive single-platform architecture gives companies unp...
Jul. 7, 2015 09:45 AM EDT Reads: 1,549