Welcome!

Industrial IoT Authors: Yeshim Deniz, Elizabeth White, SmartBear Blog, Liz McMillan, Pat Romanski

Related Topics: Industrial IoT

Industrial IoT: Article

Switching Document Views

Switching Document Views

Complex technical documentation presented on the Internet calls for user interfaces or navigational options that empower readers to quickly gain access to the information that suits their needs. If your readers are viewing documents in an Internet Explorer-only environment, you can let them select the level of detail that will be displayed by combining XML, XSLT, script, and methods of the Document Object Model.

The transformNode() method of the DOM, in particular, enables you to dynamically apply different XSL stylesheets to the same XML source document, producing different views of the same document at the click of a button.

The simple XML document in Listing 1 is structured into a hierarchy of topics with IBM's Darwin Information Typing Architecture (DITA), a DTD for creating modular documentation. (For more on DITA, see www-106.ibm.com/developerworks/xml/.) The document in Listing 1 can be displayed using a single XSLT stylesheet by embedding the xml:stylesheet processing instruction after the XML version processing instruction, as this code shows:

<?xml version="1.0" standalone="yes"?>
<?xml:stylesheet type="text/xsl" href=
"listing2.xsl"?>

When an XML document with an xml:stylesheet processing instruction is loaded into Internet Explorer 5.0 or higher, it's formatted according to the template rules in the stylesheet. (Because the example stylesheets in this article conform to the W3C's XSLT Recommendation while the MSXML parser with which Internet Explorer 5 is natively equipped does not, you must have installed at least version 3 of the MSXML parser and be running it in replace mode for the code to work. You can obtain the latest version of the MSXML parser at http://msdn.microsoft.com and install it in a few minutes.)

Because the xml:stylesheet processing instruction can apply only one stylesheet to the document, it limits readers to the view prescribed by the stylesheet named listing3.xsl. The reader, however, may prefer to view only a certain level of the document's detail. Some readers, for instance, may want to read only an abstract, others an abridged view, and still others the entire piece. You can use a scripting language that supports the DOM to dynamically apply different stylesheets to an XML source document, thereby allowing readers to switch among various views of the same Web page with the press of a button.

A W3C specification, the DOM is a platform- and language-neutral interface that provides programs and scripts with the means to dynamically access and modify the content, structure, and style of documents, including those in HTML, XHTML, and XML format. For details, see the W3C's DOM page at www.w3.org/DOM/.

The transformNode Method
It's the DOM's transformNode method that lets you dynamically apply XSLT stylesheets to an XML document. If you create two instances of the DOM's Document object and load the XML source into one of them and the XSL stylesheet into the other, you can then use the stylesheet to transform the XML source by invoking the transformNode() method.

The syntax of the transformNode() method, which is available in ASP, JScript, Visual Basic, and VBScript, goes like this:

strResult = objXMLNode.transformNode
(objStylesheet)

The objXMLNode typically takes a DOM Document object, though it can also take a node and its children within a DOM Document. The objStylesheet is usually a DOM Document instance containing a valid XSL stylesheet. The strResult, which is a string that contains the results of the XSLT transformation, can then be put into an HTML document by, for example, creating a <div id="results"></div> tag, setting a reference to it, and then using the innerHTML method to insert the string results.

Using TransformNode() to Switch Stylesheets
I've written two basic stylesheets for my source document:

  • Listing 2 displays the first level of nested topics, giving readers a summary of sorts.
  • Listing 3 displays the document's entire contents.
To enable a user with IE5 or higher running at least version 3 of the MSXML parser to select the level of detail of the document to be viewed, you'll first need to use script to load both the XML source file and the default XSLT stylesheet into the MSXML parser. The page will then have to provide users with a means to toggle between the different views while the script, when activated by a button pressed by the user, presents the document after it's transformed by the other stylesheet.

The script, which is embedded in an HTML page, appears in Listing 4, which can be downloaded at www.sys-con.com/xml/sourcec.cfm. A similar version of this script, replete with debugging logic, is available in Michael Kay's XSLT Programmer's Reference (Wrox), a book that covers XSLT in full and provides an excellent rundown of how to use XML and XSLT with Internet Explorer as well as an insightful discussion of the different versions of the MSXML parser.

After the HTML page in Listing 4 loads, the onLoad attribute of the <body> tag triggers the script's function and displays the contents of the document using the default stylesheet in Listing 2.

<body onLoad="transformPage
('listing2.xsl')">

The HTML page presents the user with two buttons, each of which specifies a different stylesheet to be used as the stylesheet parameter in the script's transformPage function without sending a request back to the server:

<button onClick=
"transformPage('listing3.xsl')">
View Entire Document</button>
<button onClick="transformPage
('listing2.xsl')">View Summary
</button>

When a user selects one of the buttons, the stylesheet specified in the argument of transformPage function is applied to the XML document and the results are inserted inside the <div id="results"> tag.

This is just a sample of what can be done when you combine XML, XSLT, script, and methods of the DOM. If you're displaying complex documentation on the Web, such methods can be expanded to develop potent interfaces that give users the power to quickly find the information that suits their needs.

More Stories By Steve Hoenisch

Steve Hoenisch is a technical writer (consultant) with Verizon
Wireless. Before becoming a technical writer and a Web developer, he
worked as a journalist and teacher. Steve has been developing Web
sites since 1996.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
The financial services market is one of the most data-driven industries in the world, yet it’s bogged down by legacy CPU technologies that simply can’t keep up with the task of querying and visualizing billions of records. In his session at 20th Cloud Expo, Karthik Lalithraj, a Principal Solutions Architect at Kinetica, discussed how the advent of advanced in-database analytics on the GPU makes it possible to run sophisticated data science workloads on the same database that is housing the rich...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st 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 and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, has been named "Bronze Sponsor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that EnterpriseTech has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effic...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. 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 ...
SYS-CON Events announced today that CHEETAH Training & Innovation will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct. 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CHEETAH Training & Innovation is a cloud consulting and IT training firm specializing in improving clients cloud strategies and infrastructures for medium to large companies.
SYS-CON Events announced today that Datanami has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datanami is a communication channel dedicated to providing insight, analysis and up-to-the-minute information about emerging trends and solutions in Big Data. The publication sheds light on all cutting-edge technologies including networking, storage and applications, and thei...