📄 0179-0182.html
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:The XML Style Mechanism:EarthWeb Inc.-</TITLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><SCRIPT><!--function displayWindow(url, width, height) { var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');}//--></SCRIPT></HEAD><BODY BGCOLOR="#FFFFFF" VLINK="#DD0000" TEXT="#000000" LINK="#DD0000" ALINK="#FF0000"><TD WIDTH="540" VALIGN="TOP"><!-- <CENTER><TABLE><TR><TD><FORM METHOD="GET" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-foldocsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="Glossary Search"></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD><TD><IMG SRC="http://www.itknowledge.com/images/dotclear.gif" WIDTH="15" HEIGHT="1"></TD><TD><FORM METHOD="POST" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-subscriptionsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE=" Book Search "></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="backlink" TYPE="hidden" VALUE="http://search.itknowledge.com:80/excite/AT-subscriptionquery.html"><INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD></TR></TABLE></CENTER> --><!-- ISBN=1575213346 //--><!-- TITLE=Presenting XML//--><!-- AUTHOR=Richard Light//--><!-- PUBLISHER=Macmillan Computer Publishing//--><!-- IMPRINT=Sams//--><!-- CHAPTER=10 //--><!-- PAGES=0179-0200 //--><!-- UNASSIGNED1 //--><!-- UNASSIGNED2 //--><P><CENTER><A HREF="../ch09/0175-0178.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0183-0187.html">Next</A></CENTER></P><A NAME="PAGENUM-179"><P>Page 179</P></A><H3><A NAME="ch10_ 1">CHAPTER 10</A></H3><H2>The XML Style <BR>Mechanism</H2><B>by Richard Light</B><P>Chapter 2, "Enter XML," briefly discussed the XMLstyle sheet language known as XS. XML needs a style languagethat goes beyond Cascading Style Sheets. In this chapter, I gointo XS in a little more detail.</P><P>Just as XML is a "profile" of the SGML standard,so XS is an application profile of the DSSSL standard (DocumentStyle and Semantics Specification Language, ISO/IEC 10179).XS's scope is to support the style sheet requirements ofXML browsers and editors. It is meant to be a baselinespecification; there is nothing to stop software providers fromdeveloping products that offer a more completeimplementation of DSSSL, or that integrate non-DSSSL extensions.</P><A NAME="PAGENUM-180"><P>Page 180</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD> <BLOCKQUOTE>You should be aware that the formal adoption of the XSspecification is still in the future. See Chapter 17, "Resolution of the XMLSpecification," for details. I have pitched my description of XS at a broad level that, inmy judgment, still will apply to XML's final specification.</BLOCKQUOTE></TD></TR></TABLE><P>This book has been processed by a DSSSL-O (XS-like) style sheet. Itwas authored in SGML and a style sheet was written to convert it to RTF(Rich Text Format). It was a straightforward job to convert this RTF file to theWord format used in this book's publishing process. I use parts of that style sheetas examples in this chapter.</P><H3><A NAME="ch10_ 2">Style Sheets: Why Bother?</A></H3><P>Start by considering why style sheets might be a good idea. If you canmanage to produce HTML pages that look really cool without any extra help,why bother with style sheets at all?</P><H4><A NAME="ch10_ 3">Separating Style From Markup</A></H4><P>One good reason for using style sheets is that moving style information toa separate style file can dramatically simplify your markup. If you look atthe source of some typical HTML pages, you will see that the markup ispacked with attributes whose only purpose is to specify how the element shouldbe displayed on the screen:</P><!-- CODE //--><PRE><bodybgcolor="#FFFFFF"text="#000000"link="#054BBB"vlink="#054BBB"background="/Images/backshadow2.gif"></PRE><!-- END CODE //--><P>or:</P><!-- CODE SNIP //--><PRE><img src="/Images/bump.gif"border=0width=50height=5align=left></PRE><!-- END CODE SNIP //--><P>Putting this information into the markup is bad for the following reasons:</P><A NAME="PAGENUM-181"><P>Page 181</P></A><UL><LI> More work: If an element type has five display-related attributes,for example, you will have to fill these in each time you add an exampleof that element type.<LI> Potential inconsistency: If you want a consistent look and feel toyour pages, it is your responsibility to ensure that you use thedisplay-related attributes in a consistent manner. This also applies whenyou make changes to the style of your pages.<LI> Inflexibility: Page display instructions are built into the pagesthemselves, making it difficult to display them any other way. Youcannot optimize the display of your pages so that they look good inevery browser software your clients might use.<LI> Obfuscation: Having all that display information in the markupmakes it harder to see the underlying structure.</UL><P>If you strip out all the style-related attributes from the two examples, youare left with the following:</P><!-- CODE SNIP //--><PRE><body></PRE><!-- END CODE SNIP //--><P>or:</P><!-- CODE SNIP //--><PRE><img src="/Images/bump.gif"></PRE><!-- END CODE SNIP //--><P>which is much clearer.</P><P>Obviously, the display-related information that was declared as attributevalues within the element's start tag has to be provided somehow; this iswhere the style sheet comes in.</P><H4><A NAME="ch10_ 4">Multiple Styles = Multiple Products</A></H4><P>Removing style information from your XML documents allows you to doeven more things with them.</P><P>Your primary purpose might be only an HTML-style information deliveryon the Web. Even within this routine type of application, you can gainbenefits from multiple style sheets. As a service provider, you can offer the following:</P><UL><LI> Large-print versions of your documents for the visually impaired<LI> Preview versions of long documents that provide an abstractand structured overview of the full text<LI> Public and private versions of documents, with confidentialdetails available only to those who have the required access level</UL><A NAME="PAGENUM-182"><P>Page 182</P></A><P>In each case, exactly the same XML document would be displayed. Thedifferences would be controlled by the style sheets associated with thatdocument. Without style sheets, you probably would be faced with creating differentforms of each document by hand to support these different requirements.</P><P>As a Web client, you might also want to use XS style sheets to control theway incoming documents look.</P><H4><A NAME="ch10_ 5">XS and Generic XML Applications</A></H4><P>After you move away from HTML-like documents and into customXML applications, a style language becomes essential.</P><P>Users have become accustomed to HTML browsers that "know about"HTML markup, and these browsers do a decent, forgiving job of renderingHTML pages. This rendering is possible because the semantics of HTML markupare widely understood and agreed upon. Even so, in some areas of markup(such as tables) a page will look sensible only if a particular browser is used.</P><P>Generally, an XML browser cannot be expected to have the knowledge todisplay the elements found within a custom application. Therefore, thebrowser needs to be fed this information, and that requires astyle sheet.</P><H3><A NAME="ch10_ 6">How Do XS Style Sheets Work?</A></H3><P>An XS style sheet controls the process of formatting a valid or well-formedXML document. It applies formatting characteristics to portions of the data.However, it cannot finish the job of paginating the document onto a screen orprinted page. That job is left to a back-endprocessor, which knows about the target environment and can implement the formatting instructions in a sensible way.</P><P>As discussed in Chapter 2, a flow object treeis what the style engine passes to the back-end processor. This flow object tree containsflow objects, which represent display elements (paragraphs, tables, table-rows, characters, and soon). The flow object tree is created by merging the source document with thestyle sheet instructions.</P><P>This discussion of the mechanics of style sheets is all getting a bitabstract. Probably the best way to understand how XS works is to jump right inand take a walk through the process. In this section I'll use the Sams.net stylesheet to format this small but well-formed XML document:</P><P><CENTER><A HREF="../ch09/0175-0178.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0183-0187.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -