📄 0183-0187.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="0179-0182.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0188-0191.html">Next</A></CENTER></P><A NAME="PAGENUM-183"><P>Page 183</P></A><!-- CODE SNIP //--><PRE><?XML version="1.0"?><p>Hello world!</p></PRE><!-- END CODE SNIP //--><H4><A NAME="ch10_ 7">The Core Expression Language</A></H4><P>Before starting, here's some background. All XS style sheets use alow-level language called the core expressionlanguage, which is based on the Scheme Programming Language. Schemeis itself a dialect of Lisp. Although you won't learn this language, a couple of basics might help you to follow theexamples of XS code that I will present in this section.</P><P>Parentheses are used to indicate procedurecalls. As an example, consider the built-in * operator that carries out multiplication. The procedure call</P><!-- CODE SNIP //--><PRE>(* 3 5)</PRE><!-- END CODE SNIP //--><P>says multiply 3 times 5, and therefore returns the result, 15. This is ratherdifferent from the way that multiplication is expressed in manyprogramming languages.</P><P>Literal values (which have a specific meaning in the XS language) areintroduced by a single quotation mark:</P><!-- CODE SNIP //--><PRE>`start</PRE><!-- END CODE SNIP //--><P>This is a different syntax from that used for ordinary strings, which cancontain anything you like:</P><!-- CODE SNIP //--><PRE>"[SAMSFT]"</PRE><!-- END CODE SNIP //--><P>The core expression language is really low-level stuff. You can think of theXS style language (which is defined using the core expression language) as ahigh-level application.</P><H4><A NAME="ch10_ 8">What's in the Style Sheet?</A></H4><P>An XS style sheet consists of many types of declarations, definitions, andrules. However, you can get a long way with just the following two:</P><UL><LI> Definitions: Defineprocedures, using the full power of the underlyingcore expression language.<LI> Construction rules:Express rules for constructing parts of the flow object tree when a certain element is encountered.</UL><P>Here are the parts of the Sams.net style sheet that you need to formatyour paragraph: two definitions and one construction rule.</P><A NAME="PAGENUM-184"><P>Page 184</P></A><P>First comes the definition of theSTANDARD-PARAGRAPH procedure:</P><!-- CODE //--><PRE>(define (STANDARD-PARAGRAPH) (make paragraph use: p-style space-after: *para-sep* quadding: `start (literal "[SAMSFT]") (process-children-trim)))</PRE><!-- END CODE //--><P>Next comes the element construction rule. It uses theSTANDARD-PARAGRAPH procedure you have just defined in the preceding code:</P><!-- CODE SNIP //--><PRE>(element P (STANDARD-PARAGRAPH))</PRE><!-- END CODE SNIP //--><P>Finally, the STANDARD-PARAGRAPH procedure contains the following line:</P><!-- CODE SNIP //--><PRE>use: p-style</PRE><!-- END CODE SNIP //--><P>This line refers to a predefined paragraph style, which is defined as follows:</P><!-- CODE SNIP //--><PRE>(define p-style (style font-size: *bf-size* line-spacing: (* *bf-size* *line-spacing-factor*)))</PRE><!-- END CODE SNIP //--><P>That's all you need from the full specification to get started. Now look ateach component in turn.</P><H4><A NAME="ch10_ 9">Procedures</A></H4><P>You first have an example of a procedure definition:</P><!-- CODE SNIP //--><PRE>(define (STANDARD-PARAGRAPH) ...)</PRE><!-- END CODE SNIP //--><P>In general, these definitions take the following form:</P><!-- CODE SNIP //--><PRE>(define (PROCNAME [arguments]) PROCEDURE-BODY)</PRE><!-- END CODE SNIP //--><P>The definitions associate the procedurePROCNAME with the code in PROCEDURE-BODY. PROCNAME can optionally have one or more arguments; this exampledoesn't have any.</P><P>You can set up any number of procedures in your XS style sheets. Ingeneral, it's a good idea to place the complex processing you need to do insideprocedures, which means you can simplify the appearance of the constructionrules for each element. For really complex processing, you can write proceduresthat call other procedures to any level of nesting.</P><A NAME="PAGENUM-185"><P>Page 185</P></A><H4><A NAME="ch10_ 10">Flow Object Classes</A></H4><P>So what is in this procedure? The first line, which follows, says that youshould construct a paragraph flow object to add to your flow object tree:</P><!-- CODE SNIP //--><PRE>(make paragraph</PRE><!-- END CODE SNIP //--><P>A paragraph flow object is just one example of aflow object class. The XS specification defines the following 25 flow object classes as mandatory:</P><UL><LI> sequence<LI> display-group<LI> simple-page-sequence<LI> paragraph<LI> paragraph-break<LI> line-field<LI> sideline<LI> character<LI> leader<LI> rule<LI> external-graphic<LI> score<LI> box<LI> alignment-point<LI> aligned-column<LI> table<LI> table-part<LI> table-column<LI> table-row<LI> table-cell<LI> table-border<LI> scroll<LI> multi-mode<LI> link<LI> marginalia</UL><A NAME="PAGENUM-186"><P>Page 186</P></A><P>The purpose of some of these will be self-evident:paragraph, external-graphic, table-row, box. Others require a deeper study of the XS specification.</P><P>In general, flow objects, when formatted, give rise toareas in the result. They can be displayed, which means that they are a separate block (like thisparagraph), or inlined, in which case they form part of the flow of text (likethis piece of code within the paragraph).</P><P>One flow object class is worth discussing in its own right—thecharacter flow object class.</P><P>You might have been wondering where the text of your document fitsinto this flow object tree. The answer is that it doesn't! Instead, by default,each individual character in the document causes a character flow object to beadded to the flow object tree.</P><P>So, in this example, you start with a sequence of characters inside ap element, like this:</P><!-- CODE SNIP //--><PRE><p>Hello world!</p></PRE><!-- END CODE SNIP //--><P>And you end up with a sequence of character flow objects inside aparagraph flow object. You might represent this in an XML-like way, as shown inthe following code:</P><!-- CODE //--><PRE> <paragraph> <character char="H"/> <character char="e"/> <character char="l"/> <character char="l"/> <character char="o"/> <character char=" "/> <character char="w"/> <character char="o"/> <character char="r"/> <character char="l"/> <character char="d"/> <character char="!"/> </paragraph></PRE><!-- END CODE //--><H4><A NAME="ch10_ 11">Characteristics</A></H4><P>The next three lines of your XS specification specify (directly or indirectly)the characteristics of your paragraph flow object, like this:</P><!-- CODE SNIP //--><PRE>use: p-stylespace-after: *para-sep*quadding: `start</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-187"><P>Page 187</P></A><P>Each type (or class) of flow object has a large number of characteristics, anyof which you can specify if you so choose. The paragraph flow object class,for example, has more than 60 characteristics.</P><P>The character flow object class has more than 40 characteristics. Thesecharacteristics allow you to specify, in minute detail, exactly how individualcharacters in your XML documents will be displayed.</P><H4><A NAME="ch10_ 12">Inheritance of Characteristics</A></H4><P>However, it is not necessary to provide a mass of information in order toget anything to display! Apart from having sensible default behavior, XSsupports the concept of inheritance of characteristics. This states that, in general, ifa characteristic isn't specified for a flow object, the value specified by thenearest ancestor of that flow object will apply instead.</P><P>For example, if the characteristic font-size isn't specified for a characterflow object (which it normally is not), the parent flow object is checked out. Inthis case, the parent flow object is your paragraph, which specifies the font size.(If the font size wasn't specified at all, a default font size of 10pt wouldapply.)</P><H4><A NAME="ch10_ 13">Characteristics of Your Sample Paragraph</A></H4><P>The following are the definitions of the paragraph characteristics that youare using in your example:</P><UL><LI>font-size: A length specifying the body size to which the fontresource should be scaled.<LI>line-spacing: A length specification giving the normalspacing between lines in the paragraph.<LI>space-after: The space to be inserted after the paragraph.<LI>quadding: One of the symbols, start, end,spread-inside, spread-outside, page-inside,page-outside, center, or justify, specifying the alignment of lines other than the last line in the paragraph.</UL><P>Returning to your STANDARD-PARAGRAPH procedure, the first line tells youto find a style called p-style and apply that style. When you unwrap thedefinition of p-style, you find that it contains specifications for two characteristics:</P><!-- CODE SNIP //--><PRE>font-size: *bf-size*line-spacing: (* *bf-size* *line-spacing-factor*)</PRE><!-- END CODE SNIP //--><P><CENTER><A HREF="0179-0182.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0188-0191.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -