📄 0188-0191.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="0183-0187.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0192-0195.html">Next</A></CENTER></P><A NAME="PAGENUM-188"><P>Page 188</P></A><P>These characteristics specify the font size and line spacing, but not in anabsolute way. Instead, they use the variable*bf-size*, which is defined elsewhere in the Sams.net style specification:</P><!-- CODE SNIP //--><PRE> (define *bf-size* (case *visual-acuity* (("normal") 10pt) (("presbyopic") 12pt) (("large-type") 24pt)))</PRE><!-- END CODE SNIP //--><P>Here you see more of the power of the core expression language. Thismeans that if the variable *visual-acuity* is set to"normal", *bf-size* will be set to 10pt. If*visual-acuity* is set to "presbyopic",*bf-size* will be set to 12pt. And if*visual-acuity* is set to "large-type",*bf-size* will be set to 24pt. Therefore, by setting the*visual-acuity* variable, you can control the font size of the whole display!</P><P>The value that *bf-size* ends up with is used directly as thefont-size characteristic of your paragraph. Theline-spacing characteristic is calculated by doing a little math on the body font size. It is multiplied by the linespacing factor, which is defined as 1.1 so that the gaps between lines are slightlylarger than the body font size. (110%, to be exact. XS supports real-number math.)</P><!-- CODE SNIP //--><PRE>(define *line-spacing-factor* 1.1)</PRE><!-- END CODE SNIP //--><P>The second line specifies the space-after characteristic:</P><!-- CODE SNIP //--><PRE>space-after: *para-sep*</PRE><!-- END CODE SNIP //--><P>Again, the space after the paragraph is given as a variable.*para-sep* is defined as half the body font size:</P><!-- CODE SNIP //--><PRE>(define *para-sep* (/ *bf-size* 2.0))</PRE><!-- END CODE SNIP //--><P>The last characteristic to be defined for your paragraph isquadding, which has the built-in value `start:</P><!-- CODE SNIP //--><PRE>quadding: `start</PRE><!-- END CODE SNIP //--><P>This means that the paragraph is left-justified.</P><P>To summarize, you have just specified that your paragraph flow object hasthe following characteristics, assuming that you set*visual-acuity* to have the value"normal":</P><!-- CODE SNIP //--><PRE>font-size: 10ptline-spacing: 11ptspace-after: 5ptquadding: `start</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-189"><P>Page 189</P></A><H4><A NAME="ch10_ 14">Element Construction Rules</A></H4><P>"What next?" you might ask! The good news is that you've already donethe hard part. Having specified the characteristics of your paragraph flowobject in the STANDARD-PARAGRAPH procedure, all you need to do now is associatethat procedure with the p element. You do this with the followingelement construction rule:</P><!-- CODE SNIP //--><PRE>(element P (STANDARD-PARAGRAPH))</PRE><!-- END CODE SNIP //--><P>This type of construction rule is central to the whole XS style process. Inthis case, the arrival of a p element triggers this rule, which in turn starts upthe process of formatting your sample paragraph.</P><H3><A NAME="ch10_ 15">Starting Up the Style Engine</A></H3><P>In the previous section, you saw how a style sheet is developed and whatit contains. In this section I will explain how an XS style sheet is actually usedto format an XML document.</P><H4><A NAME="ch10_ 16">Processing the Source Document as a Grove</A></H4><P>Before trying to process your well-formed sample XML document, theXS engine first turns the document into a grove:</P><!-- CODE SNIP //--><PRE><?XML version="1.0"?><p>Hello world!</p></PRE><!-- END CODE SNIP //--><BR><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>You might remember groves from Chapter 6, "Logical Structuresin XML Documents."</BLOCKQUOTE></TD></TR></TABLE><P>In this simple case, you can just think of the grove as a slightly larger treestructure—an XML-document node containing a processing instruction (theXML declaration), and a single element node with propertygi="p" containing 12 data character nodes with thechar property equal to the character in question.</P><P>This grove is then traversed. By default, all elements, attributespecifications, and data characters are processed (and therefore are converted to flowobjects), while all other types of nodes are ignored.</P><A NAME="PAGENUM-190"><P>Page 190</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>The decision to include only elements, attribute specifications, anddata characters is quite significant. When an XML document is represented asa grove, everything in that document becomes a node in that grove, as long asit is part of the grove plan. By default, this includes things such asprocessing instructions and the entities associated with the document. This designensures that such things do not appear in the formattedoutput.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch10_ 17">Choosing the Most Appropriate <BR>Construction Rule</A></H4><P>On encountering a node of class element in the source grove, the styleengine finds the most appropriate construction rule for it. In this case, there isn'tmuch choice! The following is your only element construction rule:</P><!-- CODE SNIP //--><PRE>(element P (STANDARD-PARAGRAPH))</PRE><!-- END CODE SNIP //--><P>However, in general, it is possible to have a number of alternativeconstruction rules, which pick out elements because</P><UL><LI> They match a query.<LI> They have a specific unique ID.<LI> They have a specific ancestry.<LI> They have a specified GI (name).</UL><P>In particular, it is often convenient to specify that elements that appear ina certain context are displayed differently. You do this by including theancestor element's name in the element construction rule. Here you have threedifferent sets of instructions for the head element, depending on whether it isinside a div1, div2, or div3 element:</P><!-- CODE SNIP //--><PRE>(element (DIV1 HEAD) (HEADING-WITH-PREFIX "a"))(element (DIV2 HEAD) (HEADING-WITH-PREFIX "b"))(element (DIV3 HEAD) (HEADING-WITH-PREFIX "c"))</PRE><!-- END CODE SNIP //--><P>These three more specific instructions for thehead element take precedence over the following element construction rule that applies tohead elements in any context. This procedure has the effect that, by default,head elements will appear italic and centered:</P><!-- CODE SNIP //--><PRE>(element HEAD (ITALIC-CENTERED-PARAGRAPH))</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-191"><P>Page 191</P></A><H4><A NAME="ch10_ 18">Formatting the Sample Paragraph's Content</A></H4><P>Now return to your sample paragraph, and see what happens next. So far,your STANDARD-PARAGRAPH procedure has created a paragraph flow object withcertain characteristics specified (and with the rest given default values, orvalues inherited from its ancestor flow objects).</P><P>Now you come to the following two lines:</P><!-- CODE SNIP //--><PRE>(literal "[SAMSFT]")(process-children-trim)</PRE><!-- END CODE SNIP //--><P>The first line uses the built-in XS commandliteral, which adds the string"[SAMSFT]" to the start of your paragraph. Well, that's the effect, butremember that you are now working with flow objects, which don't have a placefor character data. Therefore, your literal command actually creates eightcharacter flow objects, one for each character in the string, and attaches themto the paragraph flow object. It is thus equivalent to the following, but agreat deal more user-friendly:</P><!-- CODE //--><PRE>(make character char: #\[)(make character char: #\S)(make character char: #\A)(make character char: #\M)(make character char: #\S)(make character char: #\F)(make character char: #\T)(make character char: #\])</PRE><!-- END CODE //--><BR><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Each of these lines creates a character flowobject and sets its char characteristic to the correct character.#\X is the correct way of specifying the characterX in the core expression language.</BLOCKQUOTE></TD></TR></TABLE><P>Finally, you come to the following command:</P><!-- CODE SNIP //--><PRE>(process-children-trim)</PRE><!-- END CODE SNIP //--><P>This is another built-in XS command, which processes the children of thep element after stripping leading and trailing spaces. Because your sampledocument is now treated as a grove, the children of thep element include all the data characters within it, as well as any child elements. Each character is aseparate node in the source grove's tree structure.</P><P><CENTER><A HREF="0183-0187.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0192-0195.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -