|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.
Consumer IoT applications provide data about the user that just doesn’t exist in traditional PC or mobile web applications. This rich data, or “context,” enables the highly personalized consumer experiences that characterize many consumer IoT apps. This same data is also providing brands with unprecedented insight into how their connected products are being used, while, at the same time, powering highly targeted engagement and marketing opportunities. In his session at @ThingsExpo, Nathan Treloar, President and COO of Bebaio, will explore examples of brands transforming their businesses by t...
Aug. 29, 2015 11:00 AM EDT Reads: 187
SYS-CON Events announced today that Pythian, a global IT services company specializing in helping companies leverage disruptive technologies to optimize revenue-generating systems, has been named “Bronze Sponsor” of SYS-CON's 17th Cloud Expo, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. 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 DevOps to advance innovation and increase agility. Specializing in designing, imple...
Aug. 29, 2015 11:00 AM EDT Reads: 220
While many app developers are comfortable building apps for the smartphone, there is a whole new world out there. In his session at @ThingsExpo, Narayan Sainaney, Co-founder and CTO of Mojio, will discuss how the business case for connected car apps is growing and, with open platform companies having already done the heavy lifting, there really is no barrier to entry.
Aug. 29, 2015 10:30 AM EDT
WebRTC has had a real tough three or four years, and so have those working with it. Only a few short years ago, the development world were excited about WebRTC and proclaiming how awesome it was. You might have played with the technology a couple of years ago, only to find the extra infrastructure requirements were painful to implement and poorly documented. This probably left a bitter taste in your mouth, especially when things went wrong.
Aug. 29, 2015 10:15 AM EDT Reads: 413
SYS-CON Events announced today that HPM Networks will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. For 20 years, HPM Networks has been integrating technology solutions that solve complex business challenges. HPM Networks has designed solutions for both SMB and enterprise customers throughout the San Francisco Bay Area.
Aug. 29, 2015 09:30 AM EDT Reads: 839
Through WebRTC, audio and video communications are being embedded more easily than ever into applications, helping carriers, enterprises and independent software vendors deliver greater functionality to their end users. With today’s business world increasingly focused on outcomes, users’ growing calls for ease of use, and businesses craving smarter, tighter integration, what’s the next step in delivering a richer, more immersive experience? That richer, more fully integrated experience comes about through a Communications Platform as a Service which allows for messaging, screen sharing, video...
Aug. 29, 2015 08:45 AM EDT Reads: 574
SYS-CON Events announced today that Micron Technology, Inc., a global leader in advanced semiconductor systems, will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Micron’s broad portfolio of high-performance memory technologies – including DRAM, NAND and NOR Flash – is the basis for solid state drives, modules, multichip packages and other system solutions. Backed by more than 35 years of technology leadership, Micron's memory solutions enable the world's most innovative computing, consumer,...
Aug. 29, 2015 08:45 AM EDT Reads: 171
As more intelligent IoT applications shift into gear, they’re merging into the ever-increasing traffic flow of the Internet. It won’t be long before we experience bottlenecks, as IoT traffic peaks during rush hours. Organizations that are unprepared will find themselves by the side of the road unable to cross back into the fast lane. As billions of new devices begin to communicate and exchange data – will your infrastructure be scalable enough to handle this new interconnected world?
Aug. 29, 2015 07:45 AM EDT Reads: 124
As more and more data is generated from a variety of connected devices, the need to get insights from this data and predict future behavior and trends is increasingly essential for businesses. Real-time stream processing is needed in a variety of different industries such as Manufacturing, Oil and Gas, Automobile, Finance, Online Retail, Smart Grids, and Healthcare. Azure Stream Analytics is a fully managed distributed stream computation service that provides low latency, scalable processing of streaming data in the cloud with an enterprise grade SLA. It features built-in integration with Azur...
Aug. 28, 2015 07:45 PM EDT Reads: 193
Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome,” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.
Aug. 28, 2015 06:00 PM EDT Reads: 321
With the proliferation of connected devices underpinning new Internet of Things systems, Brandon Schulz, Director of Luxoft IoT – Retail, will be looking at the transformation of the retail customer experience in brick and mortar stores in his session at @ThingsExpo. Questions he will address include: Will beacons drop to the wayside like QR codes, or be a proximity-based profit driver? How will the customer experience change in stores of all types when everything can be instrumented and analyzed? As an area of investment, how might a retail company move towards an innovation methodolo...
Aug. 28, 2015 05:30 PM EDT Reads: 412
A producer of the first smartphones and tablets, presenter Lee M. Williams will talk about how he is now applying his experience in mobile technology to the design and development of the next generation of Environmental and Sustainability Services at ETwater. In his session at @ThingsExpo, Lee Williams, COO of ETwater, will talk about how he is now applying his experience in mobile technology to the design and development of the next generation of Environmental and Sustainability Services at ETwater.
Aug. 28, 2015 02:00 PM EDT
SYS-CON Events announced today that IceWarp will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. IceWarp, the leader of cloud and on-premise messaging, delivers secured email, chat, documents, conferencing and collaboration to today's mobile workforce, all in one unified interface
Aug. 28, 2015 03:00 AM EDT Reads: 363
The Internet of Things (IoT) is about the digitization of physical assets including sensors, devices, machines, gateways, and the network. It creates possibilities for significant value creation and new revenue generating business models via data democratization and ubiquitous analytics across IoT networks. The explosion of data in all forms in IoT requires a more robust and broader lens in order to enable smarter timely actions and better outcomes. Business operations become the key driver of IoT applications and projects. Business operations, IT, and data scientists need advanced analytics t...
Aug. 28, 2015 12:30 AM EDT Reads: 361
Akana has announced the availability of the new Akana Healthcare Solution. The API-driven solution helps healthcare organizations accelerate their transition to being secure, digitally interoperable businesses. It leverages the Health Level Seven International Fast Healthcare Interoperability Resources (HL7 FHIR) standard to enable broader business use of medical data. Akana developed the Healthcare Solution in response to healthcare businesses that want to increase electronic, multi-device access to health records while reducing operating costs and complying with government regulations.
Aug. 26, 2015 07:00 AM EDT Reads: 117
For IoT to grow as quickly as analyst firms’ project, a lot is going to fall on developers to quickly bring applications to market. But the lack of a standard development platform threatens to slow growth and make application development more time consuming and costly, much like we’ve seen in the mobile space. In his session at @ThingsExpo, Mike Weiner, Product Manager of the Omega DevCloud with KORE Telematics Inc., discussed the evolving requirements for developers as IoT matures and conducted a live demonstration of how quickly application development can happen when the need to comply wit...
Aug. 2, 2015 11:15 AM EDT Reads: 547
The Internet of Everything (IoE) brings together people, process, data and things to make networked connections more relevant and valuable than ever before – transforming information into knowledge and knowledge into wisdom. IoE creates new capabilities, richer experiences, and unprecedented opportunities to improve business and government operations, decision making and mission support capabilities.
Aug. 1, 2015 10:00 AM EDT Reads: 477
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. 30, 2015 07:30 PM EDT Reads: 1,561
MuleSoft has announced the findings of its 2015 Connectivity Benchmark Report on the adoption and business impact of APIs. The findings suggest traditional businesses are quickly evolving into "composable enterprises" built out of hundreds of connected software services, applications and devices. Most are embracing the Internet of Things (IoT) and microservices technologies like Docker. A majority are integrating wearables, like smart watches, and more than half plan to generate revenue with APIs within the next year.
Jul. 30, 2015 02:30 PM EDT Reads: 277
Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Opening Keynote at 16th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, d...
Jul. 30, 2015 12:00 PM EDT Reads: 2,218