|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.
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, will discuss some of the security challenges of the IoT infrastructure and relate how these aspects impact Smart Living. The material will be delivered i...
Mar. 26, 2017 09:45 PM EDT Reads: 2,027
Apache Hadoop is emerging as a distributed platform for handling large and fast incoming streams of data. Predictive maintenance, supply chain optimization, and Internet-of-Things analysis are examples where Hadoop provides the scalable storage, processing, and analytics platform to gain meaningful insights from granular data that is typically only valuable from a large-scale, aggregate view. One architecture useful for capturing and analyzing streaming data is the Lambda Architecture, represent...
Mar. 26, 2017 08:30 PM EDT Reads: 6,100
As organizations realize the scope of the Internet of Things, gaining key insights from Big Data, through the use of advanced analytics, becomes crucial. However, IoT also creates the need for petabyte scale storage of data from millions of devices. A new type of Storage is required which seamlessly integrates robust data analytics with massive scale. These storage systems will act as “smart systems” provide in-place analytics that speed discovery and enable businesses to quickly derive meaningf...
Mar. 26, 2017 07:45 PM EDT Reads: 9,583
Your homes and cars can be automated and self-serviced. Why can't your storage? From simply asking questions to analyze and troubleshoot your infrastructure, to provisioning storage with snapshots, recovery and replication, your wildest sci-fi dream has come true. In his session at @DevOpsSummit at 20th Cloud Expo, Dan Florea, Director of Product Management at Tintri, will provide a ChatOps demo where you can talk to your storage and manage it from anywhere, through Slack and similar services ...
Mar. 26, 2017 06:45 PM EDT Reads: 4,247
SYS-CON Events announced today that Ocean9will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Ocean9 provides cloud services for Backup, Disaster Recovery (DRaaS) and instant Innovation, and redefines enterprise infrastructure with its cloud native subscription offerings for mission critical SAP workloads.
Mar. 26, 2017 06:30 PM EDT Reads: 2,034
The taxi industry never saw Uber coming. Startups are a threat to incumbents like never before, and a major enabler for startups is that they are instantly “cloud ready.” If innovation moves at the pace of IT, then your company is in trouble. Why? Because your data center will not keep up with frenetic pace AWS, Microsoft and Google are rolling out new capabilities In his session at 20th Cloud Expo, Don Browning, VP of Cloud Architecture at Turner, will posit that disruption is inevitable for c...
Mar. 26, 2017 05:00 PM EDT Reads: 2,122
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.
Mar. 26, 2017 02:30 PM EDT Reads: 1,763
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great dea...
Mar. 26, 2017 02:15 PM EDT Reads: 4,380
SYS-CON Events announced today that Technologic Systems Inc., an embedded systems solutions company, will exhibit at SYS-CON's @ThingsExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Technologic Systems is an embedded systems company with headquarters in Fountain Hills, Arizona. They have been in business for 32 years, helping more than 8,000 OEM customers and building over a hundred COTS products that have never been discontinued. Technologic Systems’ pr...
Mar. 26, 2017 02:00 PM EDT Reads: 3,385
SYS-CON Events announced today that CA Technologies has been named “Platinum Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY, and the 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business – from apparel to energy – is being rewritten by software. From ...
Mar. 26, 2017 01:45 PM EDT Reads: 1,833
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend @CloudExpo | @ThingsExpo, June 6-8, 2017, at the Javits Center in New York City, NY and October 31 - November 2, 2017, Santa Clara Convention Center, CA. Learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
Mar. 26, 2017 01:45 PM EDT Reads: 8,509
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
Mar. 26, 2017 01:15 PM EDT Reads: 2,123
SYS-CON Events announced today that Loom Systems will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
Mar. 26, 2017 12:45 PM EDT Reads: 1,315
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 20th Cloud Expo, which will take place on June 6-8, 2017 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 add...
Mar. 26, 2017 12:30 PM EDT Reads: 1,125
SYS-CON Events announced today that T-Mobile will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on ...
Mar. 26, 2017 11:00 AM EDT Reads: 2,206
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), will provide an overview of various initiatives to certifiy the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldw...
Mar. 26, 2017 10:45 AM EDT Reads: 632
SYS-CON Events announced today that Infranics will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Since 2000, Infranics has developed SysMaster Suite, which is required for the stable and efficient management of ICT infrastructure. The ICT management solution developed and provided by Infranics continues to add intelligence to the ICT infrastructure through the IMC (Infra Management Cycle) based on mathemat...
Mar. 26, 2017 10:15 AM EDT Reads: 3,016
SYS-CON Events announced today that SD Times | BZ Media has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. BZ Media LLC is a high-tech media company that produces technical conferences and expositions, and publishes a magazine, newsletters and websites in the software development, SharePoint, mobile development and commercial UAV markets.
Mar. 26, 2017 09:30 AM EDT Reads: 4,315
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
Mar. 26, 2017 09:15 AM EDT Reads: 1,965
Now that the world has connected “things,” we need to build these devices as truly intelligent in order to create instantaneous and precise results. This means you have to do as much of the processing at the point of entry as you can: at the edge. The killer use cases for IoT are becoming manifest through AI engines on edge devices. An autonomous car has this dual edge/cloud analytics model, producing precise, real-time results. In his session at @ThingsExpo, John Crupi, Vice President and Eng...
Mar. 26, 2017 09:00 AM EDT Reads: 3,888