Using Inline Styles

As mentioned earlier, you can also create inline styles using the STYLE attribute, if the browser you're using understands that attribute in XML documents. Using the STYLE attribute, you can specify a rule directly. For example, here's how I style the <U> element used in the previous example using the STYLE attribute:

 <?xml version="1.0" standalone="yes"?>  <?xml-stylesheet type="text/css" href="ch09_02.css"?> <DOCUMENT>     <TITLE>The Meditations</TITLE>     <AUTHOR>By Marcus Aurelius</AUTHOR>     <SECTION>Book One</SECTION>     <P>         From my grandfather,  <U STYLE="text-decoration: underline">Verus</U>,  I learned good morals and the government of my temper.     </P>     <P>         From the reputation and remembrance of my father,         modesty and a manly character.     </P>     <P>         From my mother, piety and beneficence, and abstinence,         not only from evil deeds, but even from evil         thoughts; and further, simplicity in my way of living,         far removed from the habits of the rich.     </P>     <P>         From my great-grandfather, not to have frequented         public schools, and to have had good teachers at home,         and to know that on such things a man should spend         freely.     </P> </DOCUMENT> 

This document gives the same results you see in Figure 9-7. Note that if you want to make this document valid, you'll have to declare the STYLE attribute, which might look like this in a DTD:

 <!ELEMENT U (CDATA)*>  <!ATTLIST U STYLE CDATA #IMPLIED> 

Style purists recommend that you stay away from the STYLE attribute because using this attribute means that your style declarations will be all over the document, not just in a centralized stylesheet. However, this attribute is certainly recognized by browsers, so the choice is up to you.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net