Using XML and XSLT to Personalize a Web Site Part 2: XSL Transformation Stylesheet BasicsCreating XHTML from XML
The Original XML file
In order to have something to transform, of course we need an XML file. For this article, the XML file will be fairly straightforwardlisting the blurb, some gossip, and the administration information.
<?xml version="1.0"?> <content> <blurb> Welcome to Primary Outpost, your one-stop shop for all the latest in science fiction and fantasy news. Don't forget to check out Save Our Shows, in the news section. Your voice counts! </blurb> <gossip> <teaser> Will <person>Jane Dow</person> be leaving her role as <character>Major Pressman</character> on <tvshow>Dark Heroes</tvshow>? Rumor has it she's been offered the starring role in a new pilot for another network. </teaser> <teaser> <tvshow>Millenium Mysteries</tvshow> may be adding two new characters this season. Word is that <person>Michael Arrans</person> has been signed to play the new head of the Mystery Team, and <person>Andrew Peterson</person> may be coming on board as an alien. </teaser> <teaser> A little bird told us that someone from the cast of <tvshow>Journey to Jeopardy</tvshow> is expecting a new baby next spring. Wonder who she is? Here's a clue: she directed her first episode last month. </teaser> <teaser> <person>Merridith Garett</person>, star of the fur and feather epic <movie>Misterra, Jungle Princess</movie>, is getting married next month to long time boyfriend <person>Keith Wild</person>. They plan to settle down for a while and are looking for a show they can do together. </teaser> </gossip> <admin> Copyright 1999, 2000, 2001, Nicholas Chase -- Need help? Contact the <resource location="mailto:Webmaster@nicholaschase.com">Webmaster</resource> </admin> </content>
One of the decisions that we have to make is whether or not to include interface information, such as navigational elements, within the XML file. Because they are part of the information being provided, they can be included, but because they are also part of the look and feel, they can be added directly within the style sheet.
For simplicity's sake, we will add the interface elements directly as part of the style sheet.