📄 0196-0199.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="0192-0195.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0200-0200.html">Next</A></CENTER></P><A NAME="PAGENUM-196"><P>Page 196</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Too much use of this facility would be counterproductive. It wouldbe quite possible to end up in a position where users' markup was once againfull of attributes specifying formatting—one of the problems we set out tosolve! However, it is reassuring to know that XML will supportuser-specified formatting.</BLOCKQUOTE></TD></TR></TABLE><P>Take as another example the note elements in this book. Various types ofnotes make it into the book: straightforward notes and notes as tips andwarnings. Some other notes you never see—comments I made for my own referencewhile writing. I use the TYPE attribute to specify what type of note eachnote element is, as shown in the following:</P><!-- CODE //--><PRE><note>A plain ol' note.</note><note type="warning">A warning!</note><note type="hidden">For my eyes only ...</note></PRE><!-- END CODE //--><P>My style sheet to output the book for delivery to Sams.net has to takeaccount of these differences.</P><P>This is what I came up with. It uses a procedure calledSTANDARD-NOTE, which is called up by the element construction rule fornote:</P><!-- CODE SNIP //--><PRE>(element NOTE (STANDARD-NOTE))</PRE><!-- END CODE SNIP //--><P>Sound familiar?</P><P>The STANDARD-NOTE procedure looks like this:</P><!-- CODE //--><PRE>(define (STANDARD-NOTE) (if (attribute-string "type" (current-node)) (if (string=? (attribute-string "type" (current-node)) "hidden") (empty-sosofo) (BOXED-PARAGRAPH (attribute-string "type" (current-node)))) (BOXED-PARAGRAPH "note")))</PRE><!-- END CODE //--><P>This procedure says the following:</P><UL><LI> If theTYPE attribute is specified and its value is hidden, discardthis note.<LI> If theTYPE attribute is specified and its value is anything else,output this note as a boxed paragraph, with the value of theTYPE attribute as the heading.<LI> If theTYPE attribute isn't specified, output this note as a boxedparagraph with "note" as the heading.</UL><A NAME="PAGENUM-197"><P>Page 197</P></A><P>Even if you are a programmer, you might find the logic of this procedurea little less than obvious unless you are familiar with Lisp-type languages.Again, the point is not to provide a tutorial in the XS language, but to give youan idea of its possibilities. If you want to understand what is going on here,the following might help.</P><P>The if expression takes three arguments: a test, a consequent(then), and an alternate (else"). If the test is true, the consequent is evaluated and its valueis returned; otherwise, the alternate is evaluated and its value is returned.For example, the following returns yes because the test expression is true (3 isgreater than 2):</P><!-- CODE SNIP //--><PRE>(if (> 3 2) `yes `no)</PRE><!-- END CODE SNIP //--><P>My STANDARD-NOTE procedure contains two if expressions; the second oneis the consequent of the first.</P><P>(empty-sosofo) is a built-in command that stands for "empty specificationof sequence of flow objects." It means, in effect, "discard this node and all ofits child nodes." The ability to discard selected parts of the document'stree structure makes it possible, for example, to present an XML documentwith confidential information suppressed:</P><!-- CODE //--><PRE>(define (CHECK-SECRET) (if (attribute-string "class" (current-node)) (if (string=? (attribute-string "class" (current-node)) "secret") (empty-sosofo) (process-children))))</PRE><!-- END CODE //--><H4><A NAME="ch10_ 25">The Core Query Language</A></H4><P>The XS language includes expressions that give you access to many of theproperties of element nodes in the grove that represents your XML document.These are called, collectively, the core querylanguage.</P><P>For example, the expression (current-node) returns the element you arecurrently trying to process. You can use that expression to access the propertiesof the current node:</P><!-- CODE SNIP //--><PRE>(attribute-string "type" (current-node))</PRE><!-- END CODE SNIP //--><P>This node returns a string if the current node has aTYPE attribute whose value has been specified. Otherwise, it returns the valuefalse.</P><A NAME="PAGENUM-198"><P>Page 198</P></A><P>You also can access the properties of the parent of the current node or anyof its ancestors:</P><!-- CODE SNIP //--><PRE>(gi (parent (current-node))</PRE><!-- END CODE SNIP //--><P>This procedure call returns the gi (element type name) of the currentelement's parent.</P><H3><A NAME="ch10_ 26">Summary</A></H3><P>In this chapter, I discussed a difficult topic: the XS style sheet mechanism.</P><P>I began by reviewing the arguments for having a separate style sheetmechanism, including the following:</P><UL><LI> The simplification of markup when formatting instructionsare removed from it<LI> The consistency achieved by applying formatting as a separate exercise<LI> The ability to produce multiple products from each XML document<LI> The need for some general means of controlling the formattingof generic XML</UL><P>You saw how a simple "Hello world!" paragraph might be formatted byan XS style specification. In the process of doing this, you discovered that XSworks by converting the XML document to be formatted into a grove. It thenscans that grove and merges it with the style specification.</P><P>You found that the result is another kind of tree structure—a flow objecttree—which is a nested structure of flow objects. Everything that will appear inthe result, even data characters, is converted to a flow object. Each flow objecthas characteristics, which determine how it will be rendered in the formatted result.</P><P>The flow object tree is a slightly abstract representation of the paginatedresult you are after. It requires the cooperation of a back-end processor to turn itinto a formatted result. Depending on the delivery format chosen, this can be afixed (read-only) or a revisable result.</P><A NAME="PAGENUM-199"><P>Page 199</P></A><P>In your encounters with the XS language, you discovered that it has three levels:</P><UL><LI> The core expression language—a dialect of Scheme, which is thebasis for the whole language and provides some built-in low-level expressions<LI> The core query language, which provides access to informationabout XML document-type objects in the grove<LI> The XS style language proper, which provides high-levelcommands specifically designed to support the production of a flow object tree</UL><P>Finally, I started to explore the immense power and flexibility that XSwill offer—just as soon as we can get a grip on the XS language!</P><P><CENTER><A HREF="0192-0195.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0200-0200.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -