Welcome!

Industrial IoT Authors: Jyoti Bansal, Yeshim Deniz, Elizabeth White, SmartBear Blog, Liz McMillan

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
SYS-CON Events announced today that delaPlex 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. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
SYS-CON Events announced today that Outscale, a global pure play Infrastructure as a Service provider and strategic partner of Dassault Systèmes, 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 2010, Outscale simplifies infrastructure complexities and boosts the business agility of its customers. Outscale delivers a secure, reliable and industrial strength solution for its customers, which in...
SYS-CON Events announced today that Outscale 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. Outscale's technology makes an automated and adaptable Cloud available to businesses, supporting them in the most complex IT projects while controlling their operational aspects. You boost your IT infrastructure's reactivity, with request responses that only take a few seconds.
SYS-CON Events announced today that Systena America 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. Systena Group has been in business for various software development and verification in Japan, US, ASEAN, and China by utilizing the knowledge we gained from all types of device development for various industries including smartphones (Android/iOS), wireless communication, security technology and IoT serv...
DevOps at Cloud Expo – being held October 31 - November 2, 2017, 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 r...
Five years ago development was seen as a dead-end career, now it’s anything but – with an explosion in mobile and IoT initiatives increasing the demand for skilled engineers. But apart from having a ready supply of great coders, what constitutes true ‘DevOps Royalty’? It’ll be the ability to craft resilient architectures, supportability, security everywhere across the software lifecycle. In his keynote at @DevOpsSummit at 20th Cloud Expo, Jeffrey Scheaffer, GM and SVP, Continuous Delivery Busine...
In order to meet the rapidly changing demands of today’s customers, companies are continually forced to redefine their business strategies in order to meet these needs, stay relevant and continue to see profitable growth. IoT deployment and development is integral in this transformation, and today businesses are increasingly seeing the value of investing their resources into IoT deployments. These technologies are able increase ROI through projects such as connecting supply chains or enabling sm...
SYS-CON Events announced today that CollabNet, a global leader in enterprise software development, release automation and DevOps solutions, will be a Bronze Sponsor of SYS-CON's 20th International Cloud Expo®, taking place from June 6-8, 2017, at the Javits Center in New York City, NY. CollabNet offers a broad range of solutions with the mission of helping modern organizations deliver quality software at speed. The company’s latest innovation, the DevOps Lifecycle Manager (DLM), supports Value S...
SYS-CON Events announced today that Peak 10, Inc., a national IT infrastructure and cloud services provider, 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. Peak 10 provides reliable, tailored data center and network services, cloud and managed services. Its solutions are designed to scale and adapt to customers’ changing business needs, enabling them to lower costs, improve performance and focus intern...
Everywhere we turn in our industry we can find strong opinions about the direction, type and nature of cloud’s impact on computing and business. Another word that is used in every context in our industry is “hybrid.” In his session at 20th Cloud Expo, Alvaro Gonzalez, Director of Technical, Partner and Field Marketing at Peak 10, will use a combination of a few conceptual props and some research recently commissioned by Peak 10 to offer a real-world consideration of how the various categories of...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Super Micro Computer, Inc., a global leader in compute, storage and networking technologies, 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. Supermicro (NASDAQ: SMCI), the leading innovator in high-performance, high-efficiency server technology, is a premier provider of advanced server Building Block Solutions® for Data Center, Cloud Computing, Enterprise IT, Hadoop/...
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.
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists will look at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deli...
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.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, will motivate why realizing 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 insigh...
Existing Big Data solutions are mainly focused on the discovery and analysis of data. The solutions are scalable and highly available but tedious when swapping in and swapping out occurs in disarray and thrashing takes place. The resolution for thrashing through machine learning algorithms and support nomenclature is through simple techniques. Organizations that have been collecting large customer data are increasingly seeing the need to use the data for swapping in and out and thrashing occurs ...
SYS-CON Events announced today that delaPlex will exhibit at SYS-CON's @CloudExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
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.