|
|
|
|
|
|
|
|
XML Basics, Part IV: Formatting Output
P.G. Daly 3/15/2004 Go to page: 1 2 XSLT Applied to the Movie Catalog Example Let's wrap up our movie catalog example by creating a basic XSLT stylesheet to output the results in HTML. The source tree for our example is the MovieCatalog.xml from Part III of this series. The original XML code is:
<?xml version="1.0" ?> Before I discuss the actual stylesheet code, let me show you a snapshot of page one of the resulting output:
The following XSLT stylesheet, when applied to our XML document and opened in Internet Explorer, will produce the result we see above:
<?xml version="1.0" ?> The only change I made to our original XML file in order for it to reference the stylesheet was the following line (inserted at line 3 of the original XML): <?xml-stylesheet type="text/xsl" href="MovieCatalog.xsl"?> This line of code simply tells the XML document to apply a stylesheet and where to find it. As you can see from the output and the XSLT code, the stylesheet is a combination of straight HTML with XSLT elements strategically placed where we need to retrieve content from the XML document. While this stylesheet is fairly straightforward, it does illustrate the power of using the <xsl:for-each> element to loop through multiple instances of a particular node in the XML document. As a result, this stylesheet reacts dynamically to whatever the XML content is at a given moment in time (i.e., whether you have three or three thousand movies in your catalog). Why is This So Powerful? One of the reasons this functionality is so powerful is that it allows different organizations (internal or external) to easily communicate using the same format. For example, Division A of your company can use its own source information in whatever format it chooses. Division B can use a different format for its information. When they need to interact and communicate with each other, they can easily use XSLT to transform their data (XML) to a common format. As a result, you maintain the most flexibility between the two divisions while allowing for seamless cross-division communication and interoperability. Wrap-Up As you can see, XML and its related technologies are extremely powerful. While these past four articles only discuss the basics, it should give you enough knowledge to get started and move forward with confidence.
Go to page: 1 2
|
Intranet Journal's Tutorials |
|
Managing Editor |