www.developer.com/xml/article.php/640731
|
December 18, 2000
Let's get down to casesThe following shows another look at the xsl:attribute processing element used in this lesson. <xsl:attribute name="title">The price is What is the output attribute name? On the strength of the above description from Microsoft, we can see that the name of the attribute in the output HTML code will be title (the value of the name attribute in this processing element). What is the value of the output attribute? The value of the output attribute is the same as the content of this processing element. Therefore, the value of the output attribute will be the concatenation of
The remaining code in the XSLT file consists solely of end tags that I have discussed in earlier lessons. In summary, this XSLT file, when used to transform the given XML file will produce an HTML table containing information about the titles of certain books and the authors of those books. The <tr> element for each row of the table will have an attribute named title. The value of that attribute will contain some literal text plus the price of the book corresponding to that row. An attribute with the name title (in IE5) produces a type of behavior often referred to as a tool tip. When you point to the row with the mouse pointer and pause for a short period of time, a little message appears on the screen containing the text value of the attribute named title. For example, the text value of the attribute named title in this example is some literal text plus the price information that was extracted from the XML data. This capability doesn't appear to be supported by Netscape 4.7. If you need more information on the HTML title attribute, a good place to start looking would be at Joe Burns' HTML Goodies web site. The OutputA listing of the output HTML produced by this program is shown near the end of the lesson. I captured this HTML code using the Microsoft XSL Debugger discussed in an earlier lesson. If you load this XML file into your IE5 browser, you should see something very similar to the following in the browser window. When you point to any row (other than the top row) with your mouse pointer (and pause), you should see the price of the book displayed in a tool tip. If you view this lesson using IE5, tool tips should work here also, but they don't seem to work in Netscape 4.7.
RecapSo there you have it. The use of an XSLT file
Complete Program ListingsThe following is the complete listing for the XML file (XSL004.XML):
The following is the complete listing for the XSLT file (XSL004.XSL): <?xml version='1.0'?> The following is the output HTML produced by applying this transformation to the XML file:
About the authorRichard Baldwin is a college professor and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web. Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two. He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas. He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine. Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems. |