|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.
One of the bewildering things about DevOps is integrating the massive toolchain including the dozens of new tools that seem to crop up every year. Part of DevOps is Continuous Delivery and having a complex toolchain can add additional integration and setup to your developer environment. In his session at @DevOpsSummit at 18th Cloud Expo, Miko Matsumura, Chief Marketing Officer of Gradle Inc., will discuss which tools to use in a developer stack, how to provision the toolchain to minimize onboa...
Feb. 12, 2016 09:00 PM EST Reads: 131
Companies can harness IoT and predictive analytics to sustain business continuity; predict and manage site performance during emergencies; minimize expensive reactive maintenance; and forecast equipment and maintenance budgets and expenditures. Providing cost-effective, uninterrupted service is challenging, particularly for organizations with geographically dispersed operations.
Feb. 12, 2016 06:00 PM EST
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2015 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 ad...
Feb. 12, 2016 04:15 PM EST Reads: 428
Join us at Cloud Expo | @ThingsExpo 2016 – June 7-9 at the Javits Center in New York City and November 1-3 at the Santa Clara Convention Center in Santa Clara, CA – and deliver your unique message in a way that is striking and unforgettable by taking advantage of SYS-CON's unmatched high-impact, result-driven event / media packages.
Feb. 12, 2016 03:00 PM EST
There will be new vendors providing applications, middleware, and connected devices to support the thriving IoT ecosystem. This essentially means that electronic device manufacturers will also be in the software business. Many will be new to building embedded software or robust software. This creates an increased importance on software quality, particularly within the Industrial Internet of Things where business-critical applications are becoming dependent on products controlled by software. Qua...
Feb. 12, 2016 02:15 PM EST
SYS-CON Events announced today that Commvault, a global leader in enterprise data protection and information management, has been named “Bronze Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY, and the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Commvault is a leading provider of data protection and information management...
Feb. 12, 2016 02:15 PM EST Reads: 450
With an estimated 50 billion devices connected to the Internet by 2020, several industries will begin to expand their capabilities for retaining end point data at the edge to better utilize the range of data types and sheer volume of M2M data generated by the Internet of Things. In his session at @ThingsExpo, Don DeLoach, CEO and President of Infobright, will discuss the infrastructures businesses will need to implement to handle this explosion of data by providing specific use cases for filte...
Feb. 12, 2016 01:00 PM EST Reads: 230
SYS-CON Events announced today that Pythian, a global IT services company specializing in helping companies adopt disruptive technologies to optimize revenue-generating systems, has been named “Bronze Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2015 at the Javits Center in New York, New York. Founded in 1997, Pythian is a global IT services company that helps companies compete by adopting disruptive technologies such as cloud, Big Data, advanced analytics, and DevO...
Feb. 12, 2016 12:30 PM EST Reads: 266
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. Avere delivers a more modern architectural approach to storage that doesn’t require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbuilding of data centers ...
Feb. 12, 2016 12:30 PM EST Reads: 108
SYS-CON Events announced today that Alert Logic, Inc., the leading provider of Security-as-a-Service solutions for the cloud, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. Alert Logic, Inc., provides Security-as-a-Service for on-premises, cloud, and hybrid infrastructures, delivering deep security insight and continuous protection for customers at a lower cost than traditional security solutions. Ful...
Feb. 12, 2016 11:45 AM EST Reads: 455
Fortunately, meaningful and tangible business cases for IoT are plentiful in a broad array of industries and vertical markets. These range from simple warranty cost reduction for capital intensive assets, to minimizing downtime for vital business tools, to creating feedback loops improving product design, to improving and enhancing enterprise customer experiences. All of these business cases, which will be briefly explored in this session, hinge on cost effectively extracting relevant data from ...
Feb. 12, 2016 11:15 AM EST Reads: 143
SYS-CON Events announced today that iDevices®, the preeminent brand in the connected home industry, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. iDevices, the preeminent brand in the connected home industry, has a growing line of HomeKit-enabled products available at the largest retailers worldwide. Through the “Designed with iDevices” co-development program and its custom-built IoT Cloud Infrastruc...
Feb. 12, 2016 10:00 AM EST Reads: 134
As enterprises work to take advantage of Big Data technologies, they frequently become distracted by product-level decisions. In most new Big Data builds this approach is completely counter-productive: it presupposes tools that may not be a fit for development teams, forces IT to take on the burden of evaluating and maintaining unfamiliar technology, and represents a major up-front expense. In his session at @BigDataExpo at @ThingsExpo, Andrew Warfield, CTO and Co-Founder of Coho Data, will dis...
Feb. 12, 2016 09:30 AM EST Reads: 218
The Quantified Economy represents the total global addressable market (TAM) for IoT that, according to a recent IDC report, will grow to an unprecedented $1.3 trillion by 2019. With this the third wave of the Internet-global proliferation of connected devices, appliances and sensors is poised to take off in 2016. In his session at @ThingsExpo, David McLauchlan, CEO and co-founder of Buddy Platform, will discuss how the ability to access and analyze the massive volume of streaming data from mil...
Feb. 12, 2016 09:00 AM EST
WebSocket is effectively a persistent and fat pipe that is compatible with a standard web infrastructure; a "TCP for the Web." If you think of WebSocket in this light, there are other more hugely interesting applications of WebSocket than just simply sending data to a browser. In his session at 18th Cloud Expo, Frank Greco, Director of Technology for Kaazing Corporation, will compare other modern web connectivity methods such as HTTP/2, HTTP Streaming, Server-Sent Events and new W3C event APIs ...
Feb. 12, 2016 09:00 AM EST
SYS-CON Events announced today that Men & Mice, the leading global provider of DNS, DHCP and IP address management overlay solutions, will exhibit at SYS-CON's 18th International Cloud Expo®, which will take place on June 7-9, 2016, at the Javits Center in New York City, NY. The Men & Mice Suite overlay solution is already known for its powerful application in heterogeneous operating environments, enabling enterprises to scale without fuss. Building on a solid range of diverse platform support,...
Feb. 12, 2016 06:00 AM EST Reads: 258
Eighty percent of a data scientist’s time is spent gathering and cleaning up data, and 80% of all data is unstructured and almost never analyzed. Cognitive computing, in combination with Big Data, is changing the equation by creating data reservoirs and using natural language processing to enable analysis of unstructured data sources. This is impacting every aspect of the analytics profession from how data is mined (and by whom) to how it is delivered. This is not some futuristic vision: it's ha...
Feb. 12, 2016 05:45 AM EST Reads: 463
Silver Spring Networks, Inc. (NYSE: SSNI) extended its Internet of Things technology platform with performance enhancements to Gen5 – its fifth generation critical infrastructure networking platform. Already delivering nearly 23 million devices on five continents as one of the leading networking providers in the market, Silver Spring announced it is doubling the maximum speed of its Gen5 network to up to 2.4 Mbps, increasing computational performance by 10x, supporting simultaneous mesh communic...
Feb. 12, 2016 05:00 AM EST
The cloud promises new levels of agility and cost-savings for Big Data, data warehousing and analytics. But it’s challenging to understand all the options – from IaaS and PaaS to newer services like HaaS (Hadoop as a Service) and BDaaS (Big Data as a Service). In her session at @BigDataExpo at @ThingsExpo, Hannah Smalltree, a director at Cazena, will provide an educational overview of emerging “as-a-service” options for Big Data in the cloud. This is critical background for IT and data profes...
Feb. 12, 2016 02:30 AM EST Reads: 238
With the Apple Watch making its way onto wrists all over the world, it’s only a matter of time before it becomes a staple in the workplace. In fact, Forrester reported that 68 percent of technology and business decision-makers characterize wearables as a top priority for 2015. Recognizing their business value early on, FinancialForce.com was the first to bring ERP to wearables, helping streamline communication across front and back office functions. In his session at @ThingsExpo, Kevin Roberts...
Feb. 12, 2016 12:45 AM EST Reads: 414