Chapter 1 - Introducing the X-Team | |
XSLT For Dummies | |
by Richard Wagner | |
Hungry Minds 2002 |
You may be approaching the X-Team after having already worked with HTML. If so, when you look at XML and XSLT, its natural to view these new technologies through HTML eyes. Having a knowledge of HTML definitely gives you a head start in learning XML syntax; noting the similarities and differences between them is important. Remember Although I compare HTML and XML in this section, remember that XSL and XSLT stylesheets are both written using XML, so the same rules apply to them as to XML. XML looks a lot like HTMLIf you can read HTML, you quickly see that XML looks an awful lot like HTML in terms of its syntax. For example, a document title in HTML is defined as <title>My Document Title</title> Like HTML, the element is the primary building block of XML. Therefore, a book title in XML might be defined to look something like this: <book>War and Peace</book> Additionally, XML follows HTML in using name -value pairs inside elements to provide additional descriptive information about an element. <invoice id="110"> <company>Polar Salsa Corporation</company> </invoice> In this XML snippet, the id attribute provides additional information related to the invoice element. But XML isnt the same as HTMLHTML and XML have a definite likeness, but you should watch out for some significant variations in syntax rules. The three most important are as follows. XML is well- formedHTML has always been lenient in some of its syntax requirements, not always forcing you to have closing tags on some of the elements, such as the paragraph ( <p> ) element. For example, both of the following lines are valid HTML: <p>Hello. My name is Inigo Montoya. You killed my father. Prepare to die. and <p>Hello. My name is Inigo Montoya. You killed my father. Prepare to die.</p> In contrast, XML is much more rigid: All XML documents must be well-formed , meaning that every begin tag needs to have a matching end tag: <president>Andrew Jackson</president> XML allows shortcutsAlthough XML requires any element to have a start and end tag pair, it does allow you to combine the two tags if the element is empty, meaning that no text is provided between the start and end tags. For example, the following two lines are equivalent. <device id="3838-2020"></device> and <device id="3838-2020"/> XML is case sensitiveHTML is case insensitive, so long as you spell out the tag syntax correctly, the document is processed appropriately. Each of the following are valid HTML statements. <body bgcolor="#FFFFFF"></body> <BODY BGCOLOR="#FFFFFF"></BODY> <Body Bgcolor="#FFFFFF"></Body> On the other hand, XML is case sensitive, so the following statements arent considered equal. <quote>Get used to disappointment.</quote> <QUOTE>Get used to disappointment.</QUOTE> Tip To avoid confusion, you should consistently use either all lower- or uppercase characters for the XML, XSL, and XSLT documents that you create. However, I recommend consistently using lowercase characters because this is the convention that nearly everyone follows.
|