📄 boxes.xtp
字号:
<s1 title="Using XSL for common formatting boxes"><p>Many common formatting idioms, like boxes, are repeated throughout aweb site. Each box has the same design throughout the site, butits HTML implementation is a verbose combination of tables. Changing the site design involves changing each of the tables. Themany identical changes make the site more brittle and less changeable.<p>An XSL box formatting library lets a site create a consistentlook, keeping the design stored in one place. Instead of cuttingand pasting table definitions, the page refers to the name of a box,like <var/border-box/>, and lets XSL do the formatting.</p><s2 title="A Screen Box"><p>The first element is a simple screen box. Like the screen of thefollowing example, the <var/screen-box/> creates a rectangle with asolid background. In the following, the bgcolor and title are optional.</p><example title="Using screen-box"><screen-box bgcolor="#ff8080"><title>A Sample Box</title>This is a little bit of data.</screen-box></example><p>The example, with title looks as follows, basically the same as theexample above.</p><center><table cellspacing="3" cellpadding="3" border="0" width="60%" bgcolor="#ff8080"><caption>A Sample Box</caption><tr><td>This is a little bit of data.</td></tr></table></center><p>The XSL template gives additional flexibility to the tag. Thatcomplicates the template slightly. Any attribute in the screen-boxwill be automatically added to the table. In addition, the <title>tag is optional adding an extra $if.</p><example title="screen-box XSL">screen-box << <table cellpadding="3" cellspacing="0" border="0" width="100%" bgcolor="silver"> $for-each(@*) << $copy(); >> $if (title) << <caption>$apply-templates(title/node());</caption> >> <tr><td> $apply-templates(node()[name(.)!="title"]); </td></tr> </table>>></example></s2><s2 title="A Border Box"><p>The second box is just a different style. It has a colored borderand a colored in title bar. The HTML is entirely different, but byusing the stylesheet, the XML source can be identical. The XMLspecifies the formatting and the stylesheet carries it out.</p><example title="Using border-box"><border-box bgcolor="#ff8080"><title>A Sample Box</title>This is a little bit of data.</border-box></example><p>With a similar XML source, the result is entirely different. </p><center><table cellspacing="3" cellpadding="3" border="0" width="60%" bgcolor="#ff8080"><tr><td><font size="+1">A Sample Box</font></td></tr><tr><td> <table border=0 cellpadding=3 cellspacing=0 width="100%"> <tr><td bgcolor="white"> This is a little bit of data. </td></tr> </table></table></center><p>To provide the full flexibility of the screen-box, the attributesmust be split between the generated tables. It's straightforward, ifa bit verbose. The <var/border/> attribute, for example, needs to beconverted to a <var/cellpadding/> of an inner table.</p><example title="border-box stylesheet">border-box << <table border=0 cellspacing=0 cellpadding=1 width='100%' bgcolor="silver"> $if (@border) << $attribute(cellpadding) << $(@border) >> >> $for-each(@*[name(.)!="border" and name(.)!="cellpadding"]) << $copy(); >> $if (title) << <tr><td> <table border=0 cellpadding=0 cellspacing=0 width='100%'> <tr><td><font size="+1"> <b> $apply-templates(title/node()); </b></font></td></tr> </table> </td></tr> >> <tr><td> <table border=0 cellpadding=3 cellspacing=0 width='100%'> $for-each(@cellpadding) << $copy(); >> <tr><td bgcolor="white"> $apply-templates(node()[name(.)!="title"]); </td></tr> </table> </td></tr> </table>>></example></s2><s2 title="An Example Box"><p>The example box shows nothing new technically, but does show animportant organizational difference. screen-box and border-boxare formatting tags. An <var/example/> tag is meaningful to thesource XML. The advantage of an <var/example/> tag is that theformatting can be changed meaningfully for an entire site.</p><p>It makes sense to change the formatting of an example from ascreen-box to a border-box. It doesn't make sense to change theformatting of the border-box to a screen-box. By using moremeaningful tags like <var/example/>, the site can more easily changeto formatting to make it more readable.</p><example title="Using example"><example><title>An Example Box</title>This is a little bit of example data.</example></example><center><table cellspacing="3" cellpadding="3" border="0" width="60%" bgcolor="#ff8080"><tr><td><font size="+1">An Example Box</font></td></tr><tr><td> <table border=0 cellpadding=3 cellspacing=0 width="100%"> <tr><td bgcolor="white"> This is a little bit of example data. </td></tr> </table></table></center><p>Because the <var/example/> tag has a definite style, the XSLimplementation is simpler than the more general <var/border-box/> thatachieves a similar result.</p><example title="example stylesheet">example << <table border=0 cellspacing=0 cellpadding=1 width='100%' bgcolor="#ff8080"> $if (title) << <tr><td> <table border=0 cellpadding=0 cellspacing=0 width='100%'> <tr><td><font size="+1"> <b> $apply-templates(title/node()); </b></font></td></tr> </table> </td></tr> >> <tr><td> <table border=0 cellpadding=3 cellspacing=0 width='100%'> <tr><td bgcolor="white"> $apply-templates(node()[name(.)!="title"]); </td></tr> </table> </td></tr> </table>>></example></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -