📄 0192-0195.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="0188-0191.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0196-0199.html">Next</A></CENTER></P><A NAME="PAGENUM-192"><P>Page 192</P></A><P>You haven't issued any specific commands to say what you want donewith these characters, and you don't have to. By default, data characters areoutput to the current flow object. Putting that more formally, nodes with achar property (data characters, to you and me) have a default construction rule thatreturns and copies the char property from the source node to the newlycreated character flow object:</P><!-- CODE SNIP //--><PRE>(make character)</PRE><!-- END CODE SNIP //--><H4><A NAME="ch10_ 19">Ports</A></H4><P>The reason that these data characters end up in your paragraph flowobject, rather than somewhere else, is that the instructions to process them arenested inside the make-expression for the paragraph:</P><!-- CODE SNIP //--><PRE>(make paragraph ... (literal "[SAMSFT]") (process-children-trim))</PRE><!-- END CODE SNIP //--><P>This means that the paragraph has twocontent-expressions.</P><P>I have cheerfully stated that all of these data characters (the literalstring "[SAMSFT]" and the data characters"Hello world!" from the p element) have been added to the paragraph flow object. That's an intuitively obviousidea, but there is a name for it in the XS language.</P><P>In order to be able to add flow objects as children of an existing flowobject, that flow object has to have a port. This is a place where a list of one ormore flow objects can be attached. By default, a flow object has a single port,called the principal port. Besides the principal port, you can have additionalnamed ports, but those are only for advanced XS users.</P><P>Not every flow object has a port; for example, character flow objects neverdo. A flow object that doesn't have a port is calledan atomic flow object. Atomic flow objects are the "leaf nodes" of the flow objecttree.</P><H4><A NAME="ch10_ 20">A Generalized Result</A></H4><P>The result you have now produced—this flow object tree—is still rathergeneralized. To be sure, it describes the flow objects that are to be output, andit specifies some of their characteristics very precisely. However, it is not areal formatted page, or even a page description language such as PostScript.</P><A NAME="PAGENUM-193"><P>Page 193</P></A><P>This strategy of producing a generalized result is deliberate. XS expects towork with a back-end processor that knows about the physical targetenvironment for your formatted document. XS leaves some decisions (such as linewrapping strategy) to that back-end processor, which is intended to giveoptimal formatting performance, while allowing the style sheet to specify therequired result very precisely.</P><H4><A NAME="ch10_ 21">A Real Result!</A></H4><P>Your XS engine is tied to a back-end processor that generates RTF. Theresult can be read directly into Word. So, in this example, you have used XS toproduce a formatted result that is actually editable. If you had chosen insteadto use a back-end processor that produced PostScript, you would havean unrevisable result.</P><P>Yes, you've done it! Your XS style sheet has now produced a formattedparagraph within a Word document:</P><!-- CODE SNIP //--><PRE>[SAMSFT]Hello world!</PRE><!-- END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>You might be asking yourself what is the purpose of thestring "[SAMSFT]". It is placed at the start of each paragraph so that a Wordmacro can convert the paragraph to one that uses SamsFT (Flow Text) style. This restyling of the text was the last stage in the conversion of this book fromits SGML source to a set of Word documents that fit into the Samseditorial process.</BLOCKQUOTE></TD></TR></TABLE><P>Now review how you produced a formatted paragraph from a well-formedXML document:</P><UL><LI> Youwrote an XS style sheet, which said that p elements generatea paragraph flow object, containing the literal string"[SAMSFT]" followed by the data characters in the paragraph.<LI> You called the XS style engine and told it to apply your style sheetto your sample document.<LI> The XS style engine converted your sample document to a grove.<LI> The XS style engine then scanned the grove to produce a flowobject tree, checking each node to see whether it had non-defaultinstructions attached to it, and carrying out default processing if it didn't.</UL><A NAME="PAGENUM-194"><P>Page 194</P></A><UL><LI> The XS style engine found that thep element had an element construction rule, and obeyed it.<LI> This element construction rule generated a paragraph flow object,with some specified characteristics, containing 18 character flowobjects that each inherit the font-size characteristic from the paragraph.<LI> When rendered on the page or screen, the paragraph becomesa displayed area, with no space before it and a 5pt space after it. It is<LI>left-justified, with an 11pt gap between lines.<LI> The character flow objects are added to the paragraph as inlineareas, with a font size of 10pt.<LI> The complete flow object tree is passed to a back-end processorthat produces a real formatted result—in this case, a paragraph withinan RTF document.</UL><H3><A NAME="ch10_ 22">Some Refinements</A></H3><P>You have now been through the basic process of formatting an XMLdocument with XS, and you might want to skip to the next chapter at thispoint. That's fine. What follows isn't necessary for a basic understanding of howXS works.</P><P>In this section, you look at how to refine your XS style sheets in variousways. However, this isn't, by any means, a full overview of what XS can do.(That would be another book!)</P><P>One mark of a good style sheet language is that it lets you specifyprecisely how you want your documents to look. Think about how you can takeadvantage of the markup in your XML documents to control the formattingprocess.</P><H4><A NAME="ch10_ 23">Different Types of Construction Rules</A></H4><P>Your example used a simple element construction rule that applied to allparagraphs:</P><!-- CODE SNIP //--><PRE>(element P (STANDARD-PARAGRAPH))</PRE><!-- END CODE SNIP //--><P>However, this isn't the only type of construction rule you can specify.</P><A NAME="PAGENUM-195"><P>Page 195</P></A><P>You can specify a default construction rule that will apply to any elementthat doesn't have a rule of its own:</P><!-- CODE SNIP //--><PRE>(default (STANDARD-PARAGRAPH))</PRE><!-- END CODE SNIP //--><P>This line of code would (perhaps unwisely) make any "unmatched"element into a separate paragraph.</P><P>You've already seen that XS has a built-in feature that lets you test foran element's ancestor in an element construction rule:</P><!-- CODE SNIP //--><PRE>(element (DIV1 HEAD) (HEADING-WITH-PREFIX "a"))</PRE><!-- END CODE SNIP //--><P>This element construction rule fires only if the current node is ahead element with a div1 element as its parent. If it matches, it takes precedence overany rules for head that don't specify a parent element type.</P><P>To be even more specific, you can write id constructionrules that will fire for only the one element that has the specifiedID:</P><!-- CODE SNIP //--><PRE>(id "figure.2" (SPECIAL-GRAPHIC))</PRE><!-- END CODE SNIP //--><P>This rule applies the procedure SPECIAL-GRAPHIC to the single element (ifany) that has ID="figure.2". If this rule matches, it takes precedence over anyelement construction rule that might otherwise apply.</P><P>Clearly, this level of specificity is useful only in style sheets that aredesigned for a single document. If you want a more general means of controllingformatting based on your document's markup, you can make use of the XSstyle language within your element construction rules.</P><H4><A NAME="ch10_ 24">Using Attribute Specifications to <BR>Control Formatting</A></H4><P>One obvious thing you might want to do is vary the formatting based onattribute values. This lets you put a degree of fine control in the user'shands. Attribute specifications can be picked up and used directly in the stylesheet. You might, for example, provide an INDENT attribute that allows users tospecify the initial indentation of each paragraph:</P><!-- CODE SNIP //--><PRE><p indent="10"></PRE><!-- END CODE SNIP //--><P>Your style spec could pick up the value of theINDENT attribute, and use it directly to specify thefirst-line-start-indent property for that paragraph.</P><P><CENTER><A HREF="0188-0191.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0196-0199.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -