<?xml version="1.0" encoding="gb2312"?>

<!-- RSS generated by oioj.net on 4/16/2004 ; 感谢LeXRus提供 RSS 2.0 文档; 此文件可自由使用，但请保留此行信息 --> 
<!-- Source download URL: http://blogger.org.cn/blog/rss2.asp       -->
<rss version="2.0">

<channel>
<title>X'Me, Love</title>
<link>http://blogger.org.cn/blog/blog.asp?name=xml-linguist</link>
<description>半路和尚的博客</description>
<copyright>blogger.org.cn</copyright>
<generator>W3CHINA Blog</generator>
<webMaster>webmaster@blogger.org.cn</webMaster>
<item>
<title><![CDATA[落花]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=41938</link>
<author>xml-linguist</author>
<pubDate>2008/12/23 23:28:09</pubDate>
<description><![CDATA[
<P align=center><FONT face=楷体_GB2312 size=4>当初孤身一人时<BR>恰逢满地落杏花<BR>他日落花痕犹在<BR>今日又要落谁家</FONT></P>]]></description>
</item><item>
<title><![CDATA[人生如河九九湾]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40930</link>
<author>xml-linguist</author>
<pubDate>2008/10/30 18:47:31</pubDate>
<description><![CDATA[<A><FONT color=#0909f7 size=4>　</FONT></A>
<P><FONT color=#0909f7 size=4>（一）</FONT></P>
<P><FONT color=#0909f7 size=4>题记：某年某月和某同时落难的朋友去求某一个官僚；到官僚家门口碰上时他或许正要出去或许看见我们了就不进门了，直接把我们送到了街上。还有一次，求另外一个官僚办个手续，到了他家的院子，没让进屋却嘴里咕隆着说“坐下”。</FONT></P>
<P><FONT face=楷体_GB2312 color=#0909f7 size=4>任何一条河，都是弯弯曲曲的。河边千种风景，其实都是一样的。哪个湾里的水不是因为冲不破太厚、太高的障碍才拐弯的。拐过去了，就算是有流动的方向了；其实前面的弯还急着呢！<BR>那一帮子招呼客人在院里坐下、把客人从门口接着直接送到大街上的人，连大河湾都不是，他们当时只是一个旋涡，自己转的欢，其实根本就不知道能不能流出去。</FONT></P>
<P><FONT color=#0909f7 size=4>（二）</FONT></P>
<P><FONT color=#0909f7 size=4>题记：同一时代同一情景，求官办事，其实就是要一碗饭吃，没有任何结果，跟乞丐一般过了一年。</FONT></P>
<DIV class="leave floatLeft">
<DIV><FONT face=楷体_GB2312 color=#0909f7 size=4>吃别人的饭...？<BR>活该啊！<BR>自己做的饭，味道如何，自己吃，很清楚！<BR>不过，生啃玉米棒子的事，并不见得那么痛苦。<BR>谁说的？做客吃饭的时候，都感觉自己像别人上的一道菜。<BR>话说回来，...&nbsp;<WBR>说什么呢？<BR>他们攒下来的饭，一辈子肯定吃不完，还得别人吃。</FONT></DIV></DIV>]]></description>
</item><item>
<title><![CDATA[老师越来越像生意人，生意人越来越像老师]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40593</link>
<author>xml-linguist</author>
<pubDate>2008/10/13 0:39:51</pubDate>
<description><![CDATA[
<P>&nbsp;&nbsp;&nbsp; 老师总裁召集学生客户聚会宣布新方案，老婆负责来宾登记。学生客户们手手递钱，腿腿进门去拿“新鲜的馒头新鲜的人血吃了包好”“现场示范包听包会”的灵丹妙药。生意真的不错。</P>
<P>&nbsp;&nbsp;&nbsp; 生意人老师召集客户学员到宽敞明亮的大厅“上课”，言谈优雅举止文明，绝对传道授业解惑的姿态，真的很像老师。</P>
<P>&nbsp;&nbsp;&nbsp; 这个角落很精彩，哪个旮旯可无奈？</P>]]></description>
</item><item>
<title><![CDATA[扯人生蛋]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40592</link>
<author>xml-linguist</author>
<pubDate>2008/10/13 0:23:44</pubDate>
<description><![CDATA[
<P>&nbsp;&nbsp;&nbsp; 朋友这样对我说，“Many of us crucify ourselve between two thieves: regret for the past and fear of the future.”（我们很多人总是拿两样东西折磨自己：后悔过去，恐惧未来。）想来很有道理：无为的人基本上都是这样－埋怨淹没教训，踌躇延缓行动。</P>
<P>&nbsp;&nbsp;&nbsp; 还在什么地方读到过这么一句话，“The first half of life is spent in longing for the second and the second half in regretting the first.”（前半生期待，后半生后悔。）细细斟酌，和上面一句话还是一个道理：无奈花落去，空叹秋雨来。</P>
<P>&nbsp;&nbsp;&nbsp; 或许人生真是如此可悲，而我等芸芸必死众生竟然体会不到这种可悲。若非哲人指点，或许大千世界能把自己及其同类看得如此透彻的人真是寥寥无几。庆幸自己明了此理的同时，我又不由自主地问道：如能超脱否？</P>
<P>&nbsp;&nbsp;&nbsp; 我的答案是：否！人之所以擅于总结自己，就是因为人自封为万生之灵，不知万物亦有别样的灵气，更体会不到这种灵气的存在。人所有的品质世间万物未必没有。把一个人和一根草同时埋没在地下，就能检验出谁更具有“灵气”。</P>
<P>&nbsp;&nbsp;&nbsp; 人的思想情感，只是一种客观存在，无论是后悔、恐惧还是欣喜、狂妄。怎么表现都是非常正常的。只要像一根埋在地下的草根一样，努力寻找出头的方向就可以了。</P>
<P>&nbsp;&nbsp;&nbsp; 一个屡战屡败，或者说屡败屡战的将军，未必没有这种怨悔和感叹，只是他从未停止寻找出头之地的这个过程。</P>
<P>&nbsp;&nbsp;&nbsp; </P>]]></description>
</item><item>
<title><![CDATA[xslt学习:axis::的abbreviattion]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40591</link>
<author>xml-linguist</author>
<pubDate>2008/10/12 23:05:15</pubDate>
<description><![CDATA[
<P>Axis <FONT color=#0066ff>child::</FONT> can be be omitted from a location step as it is the default axis. </P>
<P>Axis <FONT color=#0066ff>child::</FONT> 可以省略,因为它是默认axis。</P>
<P>Axis <FONT color=#0066ff>attribute::</FONT> can be abbreviatet to <FONT color=#0066ff>@</FONT>. </P>
<P>Axis <FONT color=#0066ff>attribute::</FONT>可以缩略为<FONT color=#0066ff>@</FONT>。</P>
<P><FONT color=#0066ff>//</FONT> is short for <FONT color=#0066ff>/descendant-or-self::</FONT>, <FONT color=#0066ff>.</FONT> is short for <FONT color=#0066ff>self:: </FONT>and <FONT color=#0066ff>..</FONT> is short for <FONT color=#0033ff>parent::</FONT>. </P>
<P><FONT color=#0066ff>//</FONT> 是<FONT color=#0066ff>/descendant-or-self::</FONT>的缩略；<FONT color=#0066ff>.</FONT>是<FONT color=#0066ff>self::</FONT>的缩略；<FONT color=#0066ff>..</FONT>是<FONT color=#0033ff>parent::</FONT>的缩略。</P>
<P><FONT face=黑体 size=4>以下是示例文件。</FONT></P>
<P><FONT face=黑体 color=#0033ff size=3>一、xml文件</FONT></P>
<P>&lt;?xml version="1.0"?&gt;&nbsp; <BR>&lt;xslTutorial &gt;&nbsp; <BR>&nbsp;&lt;AAA id='a1' pos='start'&gt;&nbsp; <BR>&nbsp; &lt;BBB&nbsp; id='b1'/&gt;&nbsp; <BR>&nbsp; &lt;BBB&nbsp; id='b2'/&gt;&nbsp; <BR>&nbsp;&lt;/AAA&gt;&nbsp; <BR>&nbsp;&lt;AAA&nbsp; id='a2'&gt;&nbsp; <BR>&nbsp; &lt;BBB&nbsp; id='b3'/&gt;&nbsp; <BR>&nbsp; &lt;BBB&nbsp; id='b4'/&gt;&nbsp; <BR>&nbsp; &lt;CCC&nbsp; id='c1'&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &lt;CCC&nbsp; id='c2'/&gt;&nbsp; <BR>&nbsp; &lt;/CCC&gt;&nbsp; <BR>&nbsp; &lt;BBB&nbsp; id='b5'&gt;&nbsp; <BR>&nbsp;&nbsp;&nbsp; &lt;CCC&nbsp; id='c3'/&gt;&nbsp; <BR>&nbsp; &lt;/BBB&gt;&nbsp; <BR>&nbsp;&lt;/AAA&gt;&nbsp; <BR>&lt;/xslTutorial&gt; </P>
<P><FONT face=黑体 color=#0033ff size=3>二、xslStylesheet 1</FONT></P>
<P>&lt;xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'&gt;&nbsp; <BR>&lt;xsl:template match="AAA"&gt;&nbsp; <BR>&nbsp;<BR>&lt;H3&gt;&lt;xsl:value-of select="name()"/&gt;&nbsp; <BR>&lt;xsl:text&gt; &lt;/xsl:text&gt;&nbsp; <BR>&lt;xsl:value-of select="@id"/&gt;&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&lt;TH&gt;full&lt;/TH&gt;&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:text&gt; child::BBB/attribute::id&lt;/xsl:text&gt;&nbsp; <BR>&lt;/TD&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:text&gt; <A href="mailto:BBB/@id%3C/xsl:text">BBB/@id&lt;/xsl:text</A>&gt;&nbsp; <BR>&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:value-of select="child::BBB/attribute::id"/&gt;&nbsp; <BR>&lt;/TD&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:value-of select="<A href="mailto:BBB/@id%22/">BBB/@id"/</A>&gt;&nbsp; <BR>&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;/TABLE&gt;</P>
<P>&lt;/xsl:template&gt;&nbsp; <BR>&lt;/xsl:stylesheet&gt;&nbsp; </P>
<P>HTML output 1 </P>
<P><BR>&lt;H3&gt;AAA a1&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;child::BBB/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;BBB/@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;b1&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;b1&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;AAA a2&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;child::BBB/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;BBB/@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;b3&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;b3&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp;</P>
<H3>OUTPUT 1</H3>
<H3>AAA a1</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>child::BBB/attribute::id</TD>
<TD>BBB/@id</TD></TR>
<TR>
<TD>b1</TD>
<TD>b1</TD></TR></TBODY></TABLE></P>
<H3>AAA a2</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>child::BBB/attribute::id</TD>
<TD>BBB/@id</TD></TR>
<TR>
<TD>b3</TD>
<TD>b3</TD></TR></TBODY></TABLE>&nbsp;<BR><BR></P>
<P><FONT face=黑体 color=#0033ff size=3>三、xslStylesheet2</FONT></P>
<P>&lt;xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'&gt;&nbsp; <BR>&lt;xsl:template match="BBB"&gt;&nbsp; <BR>&nbsp;<BR>&lt;H3&gt;&lt;xsl:value-of select="name()"/&gt;&nbsp; <BR>&lt;xsl:text&gt; &lt;/xsl:text&gt;&nbsp; <BR>&lt;xsl:value-of select="@id"/&gt;&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&lt;TH&gt;full&lt;/TH&gt;&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:text&gt; parent::*/attribute::id&lt;/xsl:text&gt;&nbsp; <BR>&lt;/TD&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:text&gt; <A href="mailto:../@id%3C/xsl:text">../@id&lt;/xsl:text</A>&gt;&nbsp; <BR>&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:value-of select="parent::*/attribute::id"/&gt;&nbsp; <BR>&lt;/TD&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:value-of select="<A href="mailto:../@id%22/">../@id"/</A>&gt;&nbsp; <BR>&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;/TABLE&gt; <BR>&nbsp;<BR>&lt;/xsl:template&gt;&nbsp; <BR>&lt;/xsl:stylesheet&gt;&nbsp;</P>
<P>HTML output 2 </P>
<P><BR>&lt;H3&gt;BBB b1&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;parent::*/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;../@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;a1&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;a1&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;BBB b2&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;parent::*/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;../@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;a1&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;a1&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;BBB b3&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;parent::*/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;../@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;a2&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;a2&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;BBB b4&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;parent::*/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;../@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;a2&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;a2&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;BBB b5&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;parent::*/attribute::id&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;../@id&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;a2&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;a2&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&nbsp;</P>
<H3>OUTPUT 2</H3>
<H3>BBB b1</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>parent::*/attribute::id</TD>
<TD>../@id</TD></TR>
<TR>
<TD>a1</TD>
<TD>a1</TD></TR></TBODY></TABLE></P>
<H3>BBB b2</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>parent::*/attribute::id</TD>
<TD>../@id</TD></TR>
<TR>
<TD>a1</TD>
<TD>a1</TD></TR></TBODY></TABLE></P>
<H3>BBB b3</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>parent::*/attribute::id</TD>
<TD>../@id</TD></TR>
<TR>
<TD>a2</TD>
<TD>a2</TD></TR></TBODY></TABLE></P>
<H3>BBB b4</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>parent::*/attribute::id</TD>
<TD>../@id</TD></TR>
<TR>
<TD>a2</TD>
<TD>a2</TD></TR></TBODY></TABLE></P>
<H3>BBB b5</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>parent::*/attribute::id</TD>
<TD>../@id</TD></TR>
<TR>
<TD>a2</TD>
<TD>a2</TD></TR></TBODY></TABLE></P>
<P>&nbsp;</P>
<P><FONT face=黑体 color=#0033ff size=3>四、XSL stylesheet 3</FONT></P>
<P><BR>&lt;xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'&gt;&nbsp; <BR>&nbsp;<BR>&lt;xsl:template match="CCC"&gt;&nbsp; <BR>&nbsp;<BR>&lt;H3&gt;&lt;xsl:value-of select="name()"/&gt;&nbsp; <BR>&lt;xsl:text&gt; &lt;/xsl:text&gt;&nbsp; <BR>&lt;xsl:value-of select="@id"/&gt;&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&lt;TH&gt;full&lt;/TH&gt;&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:text&gt; name(/descendant-or-self::*)&lt;/xsl:text&gt;&nbsp; <BR>&lt;/TD&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:text&gt; name(//*)&lt;/xsl:text&gt;&nbsp; <BR>&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:value-of select="name(/descendant-or-self::*)"/&gt;&nbsp; <BR>&lt;/TD&gt;&lt;TD&gt;&nbsp; <BR>&lt;xsl:value-of select="name(//*)"/&gt;&nbsp; <BR>&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;/TABLE&gt;&nbsp; <BR>&nbsp;<BR>&lt;xsl:apply-templates/ &gt;&nbsp; <BR>&lt;/xsl:template&gt;&nbsp; <BR>&lt;/xsl:stylesheet&gt;&nbsp; </P>
<P>HTML output 3 </P>
<P><BR>&lt;H3&gt;CCC c1&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;name(/descendant-or-self::*)&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;name(//*)&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;xslTutorial&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;xslTutorial&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;CCC c2&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;name(/descendant-or-self::*)&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;name(//*)&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;xslTutorial&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;xslTutorial&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; <BR>&lt;H3&gt;CCC c3&lt;/H3&gt;&nbsp; <BR>&lt;TABLE border="1"&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TH&gt;full&lt;/TH&gt;&nbsp; <BR>&lt;TH&gt;abbreviated&lt;/TH&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;name(/descendant-or-self::*)&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;name(//*)&lt;/TD&gt;&lt;/TR&gt;&nbsp; <BR>&lt;TR&gt;&nbsp; <BR>&lt;TD&gt;xslTutorial&lt;/TD&gt;&nbsp; <BR>&lt;TD&gt;xslTutorial&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;&nbsp; </P>
<H3>OUTPUT 3</H3>
<H3>CCC c1</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>name(/descendant-or-self::*)</TD>
<TD>name(//*)</TD></TR>
<TR>
<TD>xslTutorial</TD>
<TD>xslTutorial</TD></TR></TBODY></TABLE></P>
<H3>CCC c2</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>name(/descendant-or-self::*)</TD>
<TD>name(//*)</TD></TR>
<TR>
<TD>xslTutorial</TD>
<TD>xslTutorial</TD></TR></TBODY></TABLE></P>
<H3>CCC c3</H3>
<P>
<TABLE border=1>
<TBODY>
<TR>
<TH>full</TH>
<TH>abbreviated</TH></TR>
<TR>
<TD>name(/descendant-or-self::*)</TD>
<TD>name(//*)</TD></TR>
<TR>
<TD>xslTutorial</TD>
<TD>xslTutorial</TD></TR></TBODY></TABLE></P>]]></description>
</item><item>
<title><![CDATA[UnderstandingXPath04]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40559</link>
<author>xml-linguist</author>
<pubDate>2008/10/10 12:58:03</pubDate>
<description><![CDATA[<A><FONT size=3>　</FONT></A>
<P><FONT size=3>Beyond the Basics</FONT></P>
<P><FONT size=3>Until now, the discussion has targeted single nodes wherever possible. In fact, the focus has been on how to avoid selections that yield more than one node. Although this information is very useful to get you started, it really limits your capabilities. Without creating complex expressions, you can already perform many tasks with some of the basic functionality XPath provides.</FONT></P>
<P><FONT size=3>Using a Wildcard</FONT></P>
<P><FONT size=3>Wildcard characters are common in most search-oriented functions and languages. XPath has only one wildcard character: *. You can use it only to match entire names of elements or attributes, so the expression a* does not match all elements starting with the letter a. This expression generates an error instead. Wildcards are useful when you want to drill deeper into the source XML, and the names of certain nodes (particularly parent nodes) don't matter. Listing 3.14 shows how to use a wildcard.</FONT></P>
<P><FONT size=3>Listing 3.14 Stylesheet Using a Wildcard</FONT></P>
<P><FONT color=#ff0000 size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="</FONT><A href="http://www.w3.org/1999/XSL/Transform"><FONT color=#ff0000 size=3>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT color=#ff0000 size=3>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/menu/*/dish"&gt;<BR>6:&nbsp;&nbsp; -&lt;xsl:value-of select="text()" /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT size=3>Line 5 in Listing 3.14 uses a wildcard character, so it doesn't matter whether the matched dish element is a child element of the appetizers, entrees, or desserts element. Line 6 just shows the value of the matched dish element. Listing 3.15 shows the result.</FONT></P>
<P><FONT size=3>Listing 3.15 Result from Applying Listing 3.14 to Listing 3.1</FONT></P>
<P><FONT color=#ff0000 size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt;</FONT></P>
<P><BR><FONT color=#ff0000 size=3>&nbsp;&nbsp; Crab Cakes</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Jumbo Prawns</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Smoked Salmon and Avocado Quesadilla</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Caesar Salad</FONT></P>
<P><BR><FONT color=#ff0000 size=3>&nbsp;&nbsp; Grilled Salmon</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Seafood Pasta</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Linguini al Pesto</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Rack of Lamb</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Ribs and Wings</FONT></P>
<P><BR><FONT color=#ff0000 size=3>&nbsp;&nbsp; Dame Blanche</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Chocolat Mousse</FONT></P>
<P><FONT color=#ff0000 size=3>&nbsp;&nbsp; Banana Split</FONT></P>
<P><FONT size=3>In Listing 3.15, the result yields all the dish nodes, not just those that are child nodes of a particular node.</FONT></P>
<P><FONT size=3>You can use this technique in all kinds of situations. Say that you've created a whitepaper or book using an XML document. Using a wildcard, you can select all the chapter and section headers to create a table of contents. If you don't want to get all the nodes, using just the wildcard doesn't solve your problem. However, just as with the path expressions you saw earlier, you can use predicates to refine the expression. That way, you have more control over what the wildcard actually matches. A simple example is shown in Listing 3.16.</FONT></P>
<P><FONT size=3>Listing 3.16 Stylesheet Using Wildcards and Predicates</FONT></P>
<P><FONT color=#ff0000 size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="</FONT><A href="http://www.w3.org/1999/XSL/Transform"><FONT color=#ff0000 size=3>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT color=#ff0000 size=3>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Dessert of the Day:<BR>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/*[3]/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/*[3]/dish[2]/@*[2]" /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT size=3><FONT color=#0066ff>Listing 3.16 yields the same result as Listing 3.12; the result is shown in Listing 3.13. Instead of addressing nodes by name, line 8 in Listing 3.16 uses several wildcards aided by position predicates. The desserts element is the third child element of the menu element. The /menu/*[3] section of the path expression tells the processor to take the third child element of the menu element, with no regard to the name of that element. That expression yields the desserts element, just as if it had been named. The attribute chosen is also based on a wildcard. In this case, the expression tells the processor to take the second attribute of the dish element, which is, of course, the price attribute.</FONT><BR></FONT></P>
<P><FONT color=#0066ff size=3>注：Listing 3.16中的以下两行</FONT></P>
<P><FONT color=#0066ff><FONT color=#ff0000 size=3>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/*[3]/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/*[3]/dish[2]/@*[2]" /&gt;</FONT></FONT></P>
<P><FONT color=#0066ff><FONT size=3><FONT color=#0066ff>和</FONT><FONT color=#0066ff>Listing 3.12中的以下两行</FONT></FONT></FONT></P>
<P><FONT size=3><FONT face="Times New Roman" color=#ff0000>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/desserts/dish[2]/@price" /&gt;</FONT><BR></FONT></P>
<P><FONT color=#0066ff><FONT color=#0066ff size=3>所产生的实际效果一样。</FONT></FONT></P>
<P><FONT color=#0066ff><FONT color=#0066ff><FONT size=3>结论：|直接用名称标示一个节点的路径| 和 |采用通配符加谓词说明的方式来标示一个节点的路径| ， 效果是一样的。</FONT></P>
<P><FONT size=3><BR></FONT></P></FONT></FONT>]]></description>
</item><item>
<title><![CDATA[UnderstandingXPath03]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40543</link>
<author>xml-linguist</author>
<pubDate>2008/10/9 12:02:48</pubDate>
<description><![CDATA[
<P><FONT face="Times New Roman" size=3>Selecting Attributes</FONT></P>
<P><FONT face="Times New Roman" size=3>So far, you've learned only about elements. But what about attributes? Earlier, I said that elements and attributes don't differ very much, so you might expect that you can address them in the same way, as Listing 3.10 tries to do. </FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.10 Stylesheet Trying to Select Attributes</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="</FONT><A href="http://www.w3.org/1999/XSL/Transform"><FONT face="Times New Roman" color=#f73809 size=3>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT face="Times New Roman" color=#f73809 size=3>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Dessert of the Day:<BR>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/desserts/dish[2]/price" /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT face="Times New Roman" size=3>Line 8 in Listing 3.10 tries to get the value of the price attribute of a dish element. That this approach doesn't work is obvious from the result in Listing 3.11.</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.11 Result from Applying Listing 3.10 to Listing 3.1</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&nbsp;&nbsp; Dessert of the Day:<BR>&nbsp;&nbsp; Chocolat Mousse<BR>&nbsp;&nbsp; Price:</FONT></P>
<P><FONT face="Times New Roman" size=3>The value-of element in Listing 3.10 doesn't yield a result. A gap appears in the result because no element matches the select expression. That is as it should be, because no price element exists. The dish element does, however, have a price attribute, which is what Listing 3.10 is supposed to select. What's wrong?</FONT></P>
<P><FONT face="Times New Roman" size=3>Nothing is wrong. You just need to tell the processor that it needs to match an attribute, not an element. You can tell the processor that you're looking for an attribute by adding the @ character in front of the name. So, if line 8 in Listing 3.10 is supposed to point to an attribute, the path expression should be /menu/desserts/dish[2]/@price, as shown in Listing 3.12. The result in Listing 3.13 is now correct.</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.12 Stylesheet Correctly Selecting an Attribute</FONT></P>
<P><FONT face="Times New Roman" color=#ff0000 size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="</FONT><A href="http://www.w3.org/1999/XSL/Transform"><FONT face="Times New Roman" color=#ff0000 size=3>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT face="Times New Roman" color=#ff0000 size=3>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Dessert of the Day:<BR>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/desserts/dish[2]/@price" /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.13 Result from Applying Listing 3.12 to Listing 3.1</FONT></P>
<P><FONT face="Times New Roman" color=#ff0000 size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&nbsp;&nbsp; Dessert of the Day:<BR>&nbsp;&nbsp; Chocolat Mousse<BR>&nbsp;&nbsp; Price: 5.95</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.12 produces the desired result. Because attributes don't have any child elements, you also know that no side effects will occur. The value of the attribute is always text.</FONT></P>
<P><FONT face="Times New Roman" size=3>NOTE</FONT></P>
<P><FONT face="Times New Roman" size=3>Attributes can have data types, but all are based on the text value. Data types will be thoroughly discussed on Day 10, "Working with Data Types."</FONT></P>
<P><FONT face="Times New Roman" size=3>Because attributes don't have side effects, they are much easier to work with. Also, because <FONT color=#0066ff>all attributes of an element need to have a different name, you have no trouble with matching multiple attributes (and getting only the value of the first).</FONT> The only way you can get multiple attributes is to start working with selections based on a wildcard character.</FONT></P>
<P><FONT face="Times New Roman" color=#0066ff size=3>Another point to consider is that attributes take less space in a document than elements. Elements have begin and end tags; an attribute doesn't need these tags. Because attributes have only a text value, a parser or processor can deal with them more quickly because it doesn't have to check for child elements. This is likely to have a positive effect on performance.</FONT></P>
<P><FONT face="Times New Roman" color=#0066ff size=3>注：一个元素所有的属性名称都不同，所以匹配属性时不存在像匹配元素时出现的问题，即，仅获得第一个元素的值。<BR>&nbsp;&nbsp;&nbsp; 元素有开始和结束标签，而属性没有，即，属性占有的文件空间小。因为属性只有一个值，解析器不需要检查它是否含有子元素，因此解析时更快。这好像是实际效应方面的一个优点。</FONT></P>
<P><FONT face="Times New Roman" color=#0066ff size=3>（我的体会：以前在什么地方看到的资料说，能处理成元素的尽量少用属性。这是以方便数据的自述性为目的的，因为，元素可以随意扩展，而属性不可以。现在看来，有些本来无需扩展的信息，没有必要做成元素，用属性标示可能更好。应该说，做程序的人更有体会：处理属性值比处理元素的数据速度要快一点。）<BR></FONT></P>]]></description>
</item><item>
<title><![CDATA[UnderstandingXPath02]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40527</link>
<author>xml-linguist</author>
<pubDate>2008/10/9 2:44:33</pubDate>
<description><![CDATA[
<P><FONT face="Times New Roman" size=3>Getting the Value of a Single Element</FONT></P>
<P><FONT face="Times New Roman" size=3>The problem with the code shown so far is that it acts on an element or a set of elements. Within the set of elements (such as the dish elements), no one node is singled out. If you also address a dish node instead of matching it with a template, a reasonable assumption would be that you will get the value of a single dish node. Listing 3.6 tests this assumption. </FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.6 Stylesheet Getting the Value of a dish Element</FONT></P>
<P><FONT face="Times New Roman" color=#f70909 size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="</FONT><A href="http://www.w3.org/1999/XSL/Transform"><FONT face="Times New Roman" color=#f70909 size=3>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT face="Times New Roman" color=#f70909 size=3>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; &lt;xsl:apply-templates /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9:&nbsp; &lt;xsl:template match="/menu/appetizers" /&gt;<BR>10:<BR>11:&nbsp; &lt;xsl:template match="/menu/entrees"&gt;<BR>12:&nbsp;&nbsp; &lt;xsl:value-of select="dish" /&gt;<BR>13:&nbsp; &lt;/xsl:template&gt;<BR>14:<BR>15:&nbsp; &lt;xsl:template match="/menu/desserts" /&gt;<BR>16:<BR>17: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT face="Times New Roman" size=3>In Listing 3.6, the template on line 11 matching the entrees element selects only the value of a dish node on line 12. Note that, compared to Listing 3.4, there is no template matching the dish element. The result for Listing 3.6 is shown in Listing 3.7.</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.7 Result from Applying Listing 3.6 to Listing 3.1</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt;</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>&nbsp;Grilled SalmonIn </FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.7, the assumption made for Listing 3.6 is correct. <FONT color=#0938f7>Getting the value of a dish node yields the value of exactly one dish node. But what happened to the other nodes? After all, the xsl:value-of element matches dish nodes, so it, in fact, matches a node-set. The fact that you get a single value is again a result of the default behavior of XSLT. If a node-set matches a xsl:value-of selection, only the value of the first element in the node-set is used. </FONT>The first element is the one that comes first in the source XML, according to the selection—in this case, the Grilled Salmon.</FONT></P>
<P><FONT face="Times New Roman" color=#0938f7 size=3>注：在以上Listing 3.6中的</FONT></P>
<P><FONT face="Times New Roman" size=3><FONT color=#f70909>11:&nbsp; &lt;xsl:template match="/menu/entrees"&gt;<BR>12:&nbsp;&nbsp; &lt;xsl:value-of select="dish" /&gt;<BR>13:&nbsp; &lt;/xsl:template&gt;</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT color=#0033ff size=3>这三行获取的只是一个dish的值，即/menu/entrees的第一个子元素dish。实际上，&lt;xsl:value-of select="dish" /&gt;选取的是dish的元素集，至于为什么只显示一个dish，这是xslt的默认规则。</FONT></FONT></P>
<P><FONT face="Times New Roman"><FONT color=#0033ff size=3>（我的体会：用template来定义dish和直接用xsl::value-of select=“dish”，效果是不一样的。在UnderstandingXpath01的Listing3.4中的这三行</FONT></P>
<P><FONT color=#0033ff size=3>18: &lt;xsl:template match="dish"&gt; </FONT></P>
<P><FONT color=#0033ff size=3>19: &lt;xsl:value-of select="text()" /&gt;</FONT></P>
<P><FONT color=#0033ff size=3>20: &lt;/xsl:template&gt;</FONT></P>
<P><FONT color=#0033ff size=3>就可以取得所有dish的值。感觉这一点很重要，但是初学时很容易忽略它。）</FONT></P></FONT>
<P><FONT face="Times New Roman" size=3>Now a new question arises: How do you specifically select another element in the node-set? Fortunately, you can just specify the number of the element you want to select. This, however, deviates from the path notation you are familiar with from Web sites. You need to place the number of the element you want to select between square brackets, [ and ]. Hence, you select the third dish element like this:</FONT></P>
<P><FONT face="Times New Roman" size=3>&lt;xsl:value-of select="dish[3]" /&gt;</FONT></P>
<P><FONT face="Times New Roman" size=3>NOTE</FONT></P>
<P><FONT face="Times New Roman" size=3>In many programming languages, a list of elements is numbered from 0, so element number 3 is actually the fourth element in the list. XSLT numbers a list starting with 1, so element number 3 is the third element.</FONT></P>
<P><FONT face="Times New Roman" size=3>The value between the square brackets is called a predicate, which is a literal or expression that determines whether a certain node should be included in the selection.</FONT></P>
<P><FONT face="Times New Roman" size=3>Note that the preceding example uses relative addressing, which means that the selection is done based on the current location. If that is the entrees element, the third dish element in the entrees element is selected. If the current node has no child elements named dish, the value is empty.</FONT></P>
<P><FONT face="Times New Roman" size=3>Because predicates can be expressions, they can become quite complex, testing whether an element conforms to certain criteria. As I said at the beginning of this section, I'll discuss more complex expressions later in this book. The object now is to make you familiar with the building blocks, so let's proceed with an example based on what you've seen so far. The example in Listing 3.8 creates a menu of the day from the sample XML in Listing 3.1. </FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.8 Stylesheet Creating "Today's Menu"</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="</FONT><A href="http://www.w3.org/1999/XSL/Transform"><FONT face="Times New Roman" color=#f73809 size=3>http://www.w3.org/1999/XSL/Transform</FONT></A><FONT face="Times New Roman" color=#f73809 size=3>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Today's Menu<BR>7:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="/menu/appetizers/dish[2]" /&gt;<BR>8:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="/menu/entrees/dish[3]" /&gt;<BR>9:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[1]" /&gt;<BR>10:&nbsp; &lt;/xsl:template&gt;<BR>11:<BR>12: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.8 has only one template on line 5, matching the root element. This template displays the values for different elements in Listing 3.1 using absolute addressing and number predicates. Line 7 selects the second dish element in the appetizers element; line 8, the third dish element in the entrees element; and line 9, the first dish element in the desserts element. Listing 3.9 shows the result.</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.9 Result from Applying Listing 3.8 to Listing 3.1</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt;</FONT></P>
<P><FONT face="Times New Roman" color=#f73809 size=3>&nbsp;&nbsp; Today's Menu<BR>&nbsp;&nbsp;&nbsp; Jumbo Prawns<BR>&nbsp;&nbsp;&nbsp; Linguini al Pesto<BR>&nbsp;&nbsp;&nbsp; Dame Blanche</FONT></P>
<P><FONT face="Times New Roman" size=3>Listing 3.8 contains only a template matching the root of the XML source. The rest of the stylesheet's functionality utilizes absolute addressing to get the wanted values. As you can see, this yields a list of dishes that form today's menu.</FONT></P>
<P><FONT face="Times New Roman" size=3>Earlier, you learned about the current node. After a template is fired, a certain node is considered the current node. A path expression doesn't contain a current node, but it does consist of context nodes. A context node is a part of an expression that operates on a certain node.</FONT></P>
<P><FONT face="Times New Roman" size=3>The predicates used in Listing 3.8 operate on the context node—in this case, the dish node. At one point or another, each part of the path's expression is the context node. It, however, is relevant only when you're working with predicates in a path expression. You can have predicates at several stages within the path expression, in which case the context node is the node that the predicate operates on.</FONT></P>
<P><FONT face="Times New Roman" size=3>You must realize that if no match occurs, nothing happens. This is also the case if a predicate holds a number for which no element exists. In that case, the number is just ignored. You don't see an error message or anything telling you that an element is missing. The clue is not that an element is missing, but rather that no element matches that particular rule, so the rule is never applied.</FONT></P>
<P><FONT face="Times New Roman" size=3><FONT color=#0909f7>注：以上片段所说的predicate在这个阶段暂时还可以理解，不过不敢说理解透彻。遇到问题的时候还得回过头来再学习。</FONT><BR></FONT><A><FONT face="Times New Roman" size=3>　</FONT></A></P>]]></description>
</item><item>
<title><![CDATA[UnderstandingXPath01]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40526</link>
<author>xml-linguist</author>
<pubDate>2008/10/9 0:43:01</pubDate>
<description><![CDATA[
<P><FONT size=3>So far, this lesson has been all theory. You need this theory as a foundation for practical application, which is what the rest of this lesson is all about.</FONT></P>
<P><FONT size=3>XSLT wouldn't work if it didn't have some kind of mechanism to match and select nodes and act on them. You need to be able to express which node or nodes should match. This is what XPath expressions are for. XPath is the language you use to specify which node or nodes you want to work with. Expressions in XPath can be very simple, pointing to a specific location within a document tree using absolute addressing. You can, however, make selections based on very complex rules. As you work your way through this book, you will learn to create more and more complex expressions. But, of course, you need to start simple.</FONT></P>
<P><FONT size=3>Selecting Elements</FONT></P>
<P jQuery1223481615140="9"><FONT size=3>If you're familiar with addresses on the World Wide Web, the most basic XPath expressions are easy to understand. A Web site is a hierarchy of files, just like an XML document is a hierarchy of elements. If you visit a Web site, you specify its root with the name of the Web site. For example, http://www.somesite.com points to the root or home page of the Web site. This is the same as http://www.somesite.com/, which is actually more accurate. What comes after this part of the address specifies where in the hierarchy of the site you want to be. So, http://www.somesite.com/menu/entrees points to the index file in the entrees directory, which is a child of the menu directory, which is a child of the root directory. The /menu/entrees path is especially interesting. It uniquely identifies a location within the Web site hierarchy, as shown in </FONT><A href="javascript:popUp('/content/images/chap3_0672323184/elementLinks/03fig04.jpg')"><FONT size=3>Figure 3.4</FONT></A><FONT size=3>.</FONT></P>
<P><A href="javascript:popUp('/content/images/chap3_0672323184/elementLinks/03fig04.jpg')"><FONT size=3>Figure 3.4</FONT></A><FONT size=3> Web site hierarchy.</FONT></P>
<P><A href="javascript:popUp('/content/images/chap3_0672323184/elementLinks/03fig04.jpg')"><FONT size=3>Figure 3.4</FONT></A><FONT size=3> shows part of the hierarchy for the Web site. Notice that /menu/entrees uniquely identifies the entrees node in the tree. If you want to select the desserts node, you change to /menu/desserts. Now look at Listing 3.1.</FONT></P>
<P><FONT size=3>Listing 3.1 Menu in XML Corresponding to Figure 3.4</FONT></P>
<P><FONT size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;</FONT></P>
<P><FONT size=3>2: &lt;menu&gt; </FONT></P>
<P><FONT size=3>3:&nbsp; &lt;appetizers title="Work up an Appetite"&gt; </FONT></P>
<P><FONT size=3>4:&nbsp;&nbsp; &lt;dish id="1" price="8.95"&gt;Crab Cakes&lt;/dish&gt; </FONT></P>
<P><FONT size=3>5:&nbsp;&nbsp; &lt;dish id="2" price="9.95"&gt;Jumbo Prawns&lt;/dish&gt; </FONT></P>
<P><FONT size=3>6:&nbsp;&nbsp; &lt;dish id="3" price="10.95"&gt;Smoked Salmon and Avocado Quesadilla&lt;/dish&gt; </FONT></P>
<P><FONT size=3>7:&nbsp;&nbsp; &lt;dish id="4" price="6.95"&gt;Caesar Salad&lt;/dish&gt; </FONT></P>
<P><FONT size=3>8:&nbsp; &lt;/appetizers&gt;</FONT></P>
<P><FONT size=3>9:&nbsp; &lt;entrees title="Chow Time!"&gt; </FONT></P>
<P><FONT size=3>10:&nbsp;&nbsp; &lt;dish id="5" price="19.95"&gt;Grilled Salmon&lt;/dish&gt; </FONT></P>
<P><FONT size=3>11:&nbsp;&nbsp; &lt;dish id="6" price="17.95"&gt;Seafood Pasta&lt;/dish&gt; </FONT></P>
<P><FONT size=3>12:&nbsp;&nbsp; &lt;dish id="7" price="16.95"&gt;Linguini al Pesto&lt;/dish&gt; </FONT></P>
<P><FONT size=3>13:&nbsp;&nbsp; &lt;dish id="8" price="18.95"&gt;Rack of Lamb&lt;/dish&gt; </FONT></P>
<P><FONT size=3>14:&nbsp;&nbsp; &lt;dish id="9" price="16.95"&gt;Ribs and Wings&lt;/dish&gt; </FONT></P>
<P><FONT size=3>15:&nbsp; &lt;/entrees&gt;</FONT></P>
<P><FONT size=3>16:&nbsp; &lt;desserts title="To Top It Off"&gt; </FONT></P>
<P><FONT size=3>17:&nbsp;&nbsp; &lt;dish id="10" price="6.95"&gt;Dame Blanche&lt;/dish&gt; </FONT></P>
<P><FONT size=3>18:&nbsp;&nbsp; &lt;dish id="11" price="5.95"&gt;Chocolat Mousse&lt;/dish&gt; </FONT></P>
<P><FONT size=3>19:&nbsp;&nbsp; &lt;dish id="12" price="6.95"&gt;Banana Split&lt;/dish&gt; </FONT></P>
<P><FONT size=3>20:&nbsp; &lt;/desserts&gt;</FONT></P>
<P><FONT size=3>21: &lt;/menu&gt;</FONT></P>
<P class=normaltitle><FONT size=3>NOTE</FONT></P>
<P class=note><FONT size=3>You can download the sample listings in this lesson from the publisher's Web site.</FONT></P>
<P><FONT size=3>The XML in Listing 3.1 has the same tree structure as that of the Web site depicted in </FONT><A href="javascript:popUp('/content/images/chap3_0672323184/elementLinks/03fig04.jpg')"><FONT size=3>Figure 3.4</FONT></A><FONT size=3>. So, just like in the Web site, /menu/entrees points to the entrees element in the XML document. Pointing to a certain node in an XML document with XPath is, as you can see, very simple. It is based on principles that you have probably used before, so they'll be familiar to you, even though you've never worked with XPath before. To see how this approach really works, look at Listing 3.2.</FONT></P>
<P><FONT size=3>Listing 3.2 Stylesheet Selecting the entrees Node from Listing 3.1</FONT></P>
<P><FONT size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt; </FONT></P>
<P><FONT size=3>2: &lt;xsl:stylesheet version="1.0" </FONT></P>
<P><FONT size=3>3: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;</FONT></P>
<P><FONT size=3>4: </FONT></P>
<P><FONT size=3>5: &lt;xsl:template match="/"&gt; </FONT></P>
<P><FONT size=3>6: &lt;xsl:value-of select="/menu/entrees" /&gt;</FONT></P>
<P><FONT size=3>7: &lt;/xsl:template&gt;</FONT></P>
<P><FONT size=3>8: </FONT></P>
<P><FONT size=3>9: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT size=3>The template on line 5 matches the root element of the source document. The value retrieved on line 6 is selected using the expression /menu/entrees, which matched the entrees element that is the child element of the root element menu. The result from applying Listing 3.2 to Listing 3.1 is shown in Listing 3.3.</FONT></P>
<P><FONT color=#1111ee size=3>注：第5行匹配根元素。第6行利用表达式/menu/entrees检索到的是与根元素menu的子元素entrees。</FONT></P>
<P><FONT size=3>Listing 3.3 Result from Applying Listing 3.2 to Listing 3.1</FONT></P>
<P><FONT size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt; Grilled Salmon Seafood Pasta Linguini al Pesto Rack of Lamb Ribs and Wings</FONT></P>
<P class=normaltitle><FONT size=3>NOTE</FONT></P>
<P class=note><FONT size=3>Be aware that the preceding sample was run with the Saxon processor. If you use another processor, the result might be slightly different. MSXSL generates UTF-16 output by default, so the result when using MSXSL will have spaces between each letter.</FONT></P>
<P align=left><FONT size=3>Listing 3.3 shows the value of all the child nodes of the entrees node. If you remember yesterday's lesson, that is exactly right, as line 6 of Listing 3.2 asks for the value of the entrees node. That node's value contains all its descendant nodes. Getting its value yields the text value of the descendant elements. This scenario is a bit confusing because it looks like Listing 3.2 actually selects a node-set consisting of all the child elements of the entrees node. If the entrees node also contains a text value, you would see that this isn't true. You can, however, create an additional template to handle the dish elements, as shown in Listing 3.4.</FONT></P>
<P><FONT color=#0033ff size=3>注：Listing 3.3显示的是entrees节点的所有子节点的值。这个节点包含所有的子孙节点，获取值就是子孙节点的值。这种情况有点令人迷惑：它实际获取的是包含所有子孙节点的一个节点集。如果entrees节点本身也含有值的话，情况会变化的。让然，你可以继续用template深入到它的子节点去处理dish元素。</FONT></P>
<P><FONT color=#0033ff size=3>（我的体会：子（或孙）节点的值归属于父（或祖）节点，即，如果你不对子孙节点进一步定义的话，匹配父（或祖）节点时获得的值就是子（或孙）节点的值。这是xslt默认的规则。如果你详细定义了子节点，那么这一默认值对于相应的父（或祖）节点无效。）</FONT></P>
<P><FONT size=3>Listing 3.4 Stylesheet with More Control over dish Elements</FONT></P>
<P><FONT size=3>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt; </FONT></P>
<P><FONT size=3>2: &lt;xsl:stylesheet version="1.0" </FONT></P>
<P><FONT size=3>3: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;</FONT></P>
<P><FONT size=3>4: </FONT></P>
<P><FONT size=3>5: &lt;xsl:template match="/"&gt;</FONT></P>
<P><FONT size=3>6: &lt;xsl:apply-templates /&gt; </FONT></P>
<P><FONT size=3>7: &lt;/xsl:template&gt;</FONT></P>
<P><FONT size=3>8:</FONT></P>
<P><FONT size=3>9: &lt;xsl:template match="/menu/appetizers" /&gt; </FONT></P>
<P><FONT size=3>10:</FONT></P>
<P><FONT size=3>11: &lt;xsl:template match="/menu/entrees"&gt;</FONT></P>
<P><FONT size=3>12: Entrees: </FONT></P>
<P><FONT size=3>13: &lt;xsl:apply-templates /&gt;</FONT></P>
<P><FONT size=3>14: &lt;/xsl:template&gt;</FONT></P>
<P><FONT size=3>15: </FONT></P>
<P><FONT size=3>16: &lt;xsl:template match="/menu/desserts" /&gt;</FONT></P>
<P><FONT size=3>17: </FONT></P>
<P><FONT size=3>18: &lt;xsl:template match="dish"&gt; </FONT></P>
<P><FONT size=3>19: &lt;xsl:value-of select="text()" /&gt;</FONT></P>
<P><FONT size=3>20: &lt;/xsl:template&gt;</FONT></P>
<P><FONT size=3>21: </FONT></P>
<P><FONT size=3>22: &lt;/xsl:stylesheet&gt;</FONT></P>
<P><FONT size=3>In Listing 3.4, note that lines 9 and 16 effectively ignore the appetizers and desserts nodes in Listing 3.1 to keep the result small and to the point. The result of applying Listing 3.4 to Listing 3.1 is shown in Listing 3.5.</FONT></P>
<P><FONT color=#0033ff size=3>注：第9和16行实际上对于appetizers节点desserts的子节点的值不处理，因为text()值只对第11到14行中定义明确的entrees节点有效。</FONT></P>
<P><FONT size=3>Listing 3.5 Result from Applying Listing 3.4 to Listing 3.1</FONT></P>
<P><FONT size=3>&lt;?xml version="1.0" encoding="utf-8"?&gt; </FONT></P>
<P><FONT size=3>&nbsp; Entrees: </FONT></P>
<P><FONT size=3>&nbsp;&nbsp; Grilled Salmon </FONT></P>
<P><FONT size=3>&nbsp;&nbsp; Seafood Pasta </FONT></P>
<P><FONT size=3>&nbsp;&nbsp; Linguini al Pesto </FONT></P>
<P><FONT size=3>&nbsp;&nbsp; Rack of Lamb </FONT></P>
<P><FONT size=3>&nbsp;&nbsp; Ribs and Wings</FONT></P>
<P><FONT size=3>In Listing 3.5, each dish node is now handled separately. The hyphen (-) in front of each dish shows that this is really the case. The whitespace appears, as I said before, because of the processor's default whitespace rules.</FONT></P>]]></description>
</item><item>
<title><![CDATA[Understanding XPath]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40505</link>
<author>xml-linguist</author>
<pubDate>2008/10/8 2:47:30</pubDate>
<description><![CDATA[
<P>So far, this lesson has been all theory. You need this theory as a foundation for practical application, which is what the rest of this lesson is all about.</P>
<P>XSLT wouldn't work if it didn't have some kind of mechanism to match and select nodes and act on them. You need to be able to express which node or nodes should match. This is what XPath expressions are for. XPath is the language you use to specify which node or nodes you want to work with. Expressions in XPath can be very simple, pointing to a specific location within a document tree using absolute addressing. You can, however, make selections based on very complex rules. As you work your way through this book, you will learn to create more and more complex expressions. But, of course, you need to start simple.</P>
<P>Selecting Elements<BR>If you're familiar with addresses on the World Wide Web, the most basic XPath expressions are easy to understand. A Web site is a hierarchy of files, just like an XML document is a hierarchy of elements. If you visit a Web site, you specify its root with the name of the Web site. For example, <A href="http://www.somesite.com/">http://www.somesite.com</A> points to the root or home page of the Web site. This is the same as <A href="http://www.somesite.com/">http://www.somesite.com/</A>, which is actually more accurate. What comes after this part of the address specifies where in the hierarchy of the site you want to be. So, <A href="http://www.somesite.com/menu/entrees">http://www.somesite.com/menu/entrees</A> points to the index file in the entrees directory, which is a child of the menu directory, which is a child of the root directory. The /menu/entrees path is especially interesting. It uniquely identifies a location within the Web site hierarchy, as shown in Figure 3.4.</P>
<P>Figure 3.4 Web site hierarchy.</P>
<P>Figure 3.4 shows part of the hierarchy for the Web site. Notice that /menu/entrees uniquely identifies the entrees node in the tree. If you want to select the desserts node, you change to /menu/desserts. Now look at Listing 3.1.</P>
<P>Listing 3.1 Menu in XML Corresponding to Figure 3.4<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;menu&gt;<BR>3:&nbsp; &lt;appetizers title="Work up an Appetite"&gt;<BR>4:&nbsp;&nbsp; &lt;dish id="1" price="8.95"&gt;Crab Cakes&lt;/dish&gt;<BR>5:&nbsp;&nbsp; &lt;dish id="2" price="9.95"&gt;Jumbo Prawns&lt;/dish&gt;<BR>6:&nbsp;&nbsp; &lt;dish id="3" price="10.95"&gt;Smoked Salmon and Avocado Quesadilla&lt;/dish&gt;<BR>7:&nbsp;&nbsp; &lt;dish id="4" price="6.95"&gt;Caesar Salad&lt;/dish&gt;<BR>8:&nbsp; &lt;/appetizers&gt;<BR>9:&nbsp; &lt;entrees title="Chow Time!"&gt;<BR>10:&nbsp;&nbsp; &lt;dish id="5" price="19.95"&gt;Grilled Salmon&lt;/dish&gt;<BR>11:&nbsp;&nbsp; &lt;dish id="6" price="17.95"&gt;Seafood Pasta&lt;/dish&gt;<BR>12:&nbsp;&nbsp; &lt;dish id="7" price="16.95"&gt;Linguini al Pesto&lt;/dish&gt;<BR>13:&nbsp;&nbsp; &lt;dish id="8" price="18.95"&gt;Rack of Lamb&lt;/dish&gt;<BR>14:&nbsp;&nbsp; &lt;dish id="9" price="16.95"&gt;Ribs and Wings&lt;/dish&gt;<BR>15:&nbsp; &lt;/entrees&gt;<BR>16:&nbsp; &lt;desserts title="To Top It Off"&gt;<BR>17:&nbsp; &lt;dish id="10" price="6.95"&gt;Dame Blanche&lt;/dish&gt;<BR>18:&nbsp; &lt;dish id="11" price="5.95"&gt;Chocolat Mousse&lt;/dish&gt;<BR>19:&nbsp; &lt;dish id="12" price="6.95"&gt;Banana Split&lt;/dish&gt;<BR>20: &lt;/desserts&gt;<BR>21: &lt;/menu&gt;NOTE</P>
<P>You can download the sample listings in this lesson from the publisher's Web site.</P>
<P>The XML in Listing 3.1 has the same tree structure as that of the Web site depicted in Figure 3.4. So, just like in the Web site, /menu/entrees points to the entrees element in the XML document. Pointing to a certain node in an XML document with XPath is, as you can see, very simple. It is based on principles that you have probably used before, so they'll be familiar to you, even though you've never worked with XPath before. To see how this approach really works, look at Listing 3.2.</P>
<P>Listing 3.2 Stylesheet Selecting the entrees Node from Listing 3.1<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/entrees" /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9: &lt;/xsl:stylesheet&gt;The template on line 5 matches the root element of the source document. The value retrieved on line 6 is selected using the expression /menu/entrees, which matched the entrees element that is the child element of the root element menu. The result from applying Listing 3.2 to Listing 3.1 is shown in Listing 3.3.</P>
<P>Listing 3.3 Result from Applying Listing 3.2 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&nbsp; Grilled Salmon<BR>&nbsp; Seafood Pasta<BR>&nbsp; Linguini al Pesto<BR>&nbsp; Rack of Lamb<BR>&nbsp; Ribs and WingsNOTE</P>
<P>Be aware that the preceding sample was run with the Saxon processor. If you use another processor, the result might be slightly different. MSXSL generates UTF-16 output by default, so the result when using MSXSL will have spaces between each letter.</P>
<P>Listing 3.3 shows the value of all the child nodes of the entrees node. If you remember yesterday's lesson, that is exactly right, as line 6 of Listing 3.2 asks for the value of the entrees node. That node's value contains all its descendant nodes. Getting its value yields the text value of the descendant elements. This scenario is a bit confusing because it looks like Listing 3.2 actually selects a node-set consisting of all the child elements of the entrees node. If the entrees node also contains a text value, you would see that this isn't true. You can, however, create an additional template to handle the dish elements, as shown in Listing 3.4.</P>
<P>Listing 3.4 Stylesheet with More Control over dish Elements<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; &lt;xsl:apply-templates /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9:&nbsp; &lt;xsl:template match="/menu/appetizers" /&gt;<BR>10:<BR>11:&nbsp; &lt;xsl:template match="/menu/entrees"&gt;<BR>12:&nbsp;&nbsp; Entrees:<BR>13:&nbsp;&nbsp; &lt;xsl:apply-templates /&gt;<BR>14:&nbsp; &lt;/xsl:template&gt;<BR>15:<BR>16:&nbsp; &lt;xsl:template match="/menu/desserts" /&gt;<BR>17:<BR>18:&nbsp; &lt;xsl:template match="dish"&gt;<BR>19:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="text()" /&gt;<BR>20:&nbsp; &lt;/xsl:template&gt;<BR>21:<BR>22: &lt;/xsl:stylesheet&gt;In Listing 3.4, note that lines 9 and 16 effectively ignore the appetizers and desserts nodes in Listing 3.1 to keep the result small and to the point. The result of applying Listing 3.4 to Listing 3.1 is shown in Listing 3.5.</P>
<P>Listing 3.5 Result from Applying Listing 3.4 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;</P>
<P><BR>&nbsp;&nbsp; Entrees:</P>
<P> <BR>&nbsp; Grilled Salmon</P>
<P>&nbsp; Seafood Pasta</P>
<P>&nbsp; Linguini al Pesto</P>
<P>&nbsp; Rack of Lamb</P>
<P>&nbsp; Ribs and WingsIn Listing 3.5, each dish node is now handled separately. The hyphen (-) in front of each dish shows that this is really the case. The whitespace appears, as I said before, because of the processor's default whitespace rules.</P>
<P>Getting the Value of a Single Element<BR>The problem with the code shown so far is that it acts on an element or a set of elements. Within the set of elements (such as the dish elements), no one node is singled out. If you also address a dish node instead of matching it with a template, a reasonable assumption would be that you will get the value of a single dish node. Listing 3.6 tests this assumption. </P>
<P>Listing 3.6 Stylesheet Getting the Value of a dish Element<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; &lt;xsl:apply-templates /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9:&nbsp; &lt;xsl:template match="/menu/appetizers" /&gt;<BR>10:<BR>11:&nbsp; &lt;xsl:template match="/menu/entrees"&gt;<BR>12:&nbsp;&nbsp; &lt;xsl:value-of select="dish" /&gt;<BR>13:&nbsp; &lt;/xsl:template&gt;<BR>14:<BR>15:&nbsp; &lt;xsl:template match="/menu/desserts" /&gt;<BR>16:<BR>17: &lt;/xsl:stylesheet&gt;In Listing 3.6, the template on line 11 matching the entrees element selects only the value of a dish node on line 12. Note that, compared to Listing 3.4, there is no template matching the dish element. The result for Listing 3.6 is shown in Listing 3.7.</P>
<P>Listing 3.7 Result from Applying Listing 3.6 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;</P>
<P>&nbsp;Grilled SalmonIn Listing 3.7, the assumption made for Listing 3.6 is correct. Getting the value of a dish node yields the value of exactly one dish node. But what happened to the other nodes? After all, the xsl:value-of element matches dish nodes, so it, in fact, matches a node-set. The fact that you get a single value is again a result of the default behavior of XSLT. If a node-set matches a xsl:value-of selection, only the value of the first element in the node-set is used. The first element is the one that comes first in the source XML, according to the selection—in this case, the Grilled Salmon.</P>
<P>Now a new question arises: How do you specifically select another element in the node-set? Fortunately, you can just specify the number of the element you want to select. This, however, deviates from the path notation you are familiar with from Web sites. You need to place the number of the element you want to select between square brackets, [ and ]. Hence, you select the third dish element like this:</P>
<P>&lt;xsl:value-of select="dish[3]" /&gt;NOTE</P>
<P>In many programming languages, a list of elements is numbered from 0, so element number 3 is actually the fourth element in the list. XSLT numbers a list starting with 1, so element number 3 is the third element.</P>
<P>The value between the square brackets is called a predicate, which is a literal or expression that determines whether a certain node should be included in the selection.</P>
<P>Note that the preceding example uses relative addressing, which means that the selection is done based on the current location. If that is the entrees element, the third dish element in the entrees element is selected. If the current node has no child elements named dish, the value is empty.</P>
<P>Because predicates can be expressions, they can become quite complex, testing whether an element conforms to certain criteria. As I said at the beginning of this section, I'll discuss more complex expressions later in this book. The object now is to make you familiar with the building blocks, so let's proceed with an example based on what you've seen so far. The example in Listing 3.8 creates a menu of the day from the sample XML in Listing 3.1. </P>
<P>Listing 3.8 Stylesheet Creating "Today's Menu"<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Today's Menu<BR>7:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="/menu/appetizers/dish[2]" /&gt;<BR>8:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="/menu/entrees/dish[3]" /&gt;<BR>9:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[1]" /&gt;<BR>10:&nbsp; &lt;/xsl:template&gt;<BR>11:<BR>12: &lt;/xsl:stylesheet&gt;Listing 3.8 has only one template on line 5, matching the root element. This template displays the values for different elements in Listing 3.1 using absolute addressing and number predicates. Line 7 selects the second dish element in the appetizers element; line 8, the third dish element in the entrees element; and line 9, the first dish element in the desserts element. Listing 3.9 shows the result.</P>
<P>Listing 3.9 Result from Applying Listing 3.8 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&nbsp;&nbsp; Today's Menu<BR>&nbsp;&nbsp;&nbsp; Jumbo Prawns<BR>&nbsp;&nbsp;&nbsp; Linguini al Pesto<BR>&nbsp;&nbsp;&nbsp; Dame BlancheListing 3.8 contains only a template matching the root of the XML source. The rest of the stylesheet's functionality utilizes absolute addressing to get the wanted values. As you can see, this yields a list of dishes that form today's menu.</P>
<P>Earlier, you learned about the current node. After a template is fired, a certain node is considered the current node. A path expression doesn't contain a current node, but it does consist of context nodes. A context node is a part of an expression that operates on a certain node.</P>
<P>The predicates used in Listing 3.8 operate on the context node—in this case, the dish node. At one point or another, each part of the path's expression is the context node. It, however, is relevant only when you're working with predicates in a path expression. You can have predicates at several stages within the path expression, in which case the context node is the node that the predicate operates on.</P>
<P>You must realize that if no match occurs, nothing happens. This is also the case if a predicate holds a number for which no element exists. In that case, the number is just ignored. You don't see an error message or anything telling you that an element is missing. The clue is not that an element is missing, but rather that no element matches that particular rule, so the rule is never applied.</P>
<P>Selecting Attributes<BR>So far, you've learned only about elements. But what about attributes? Earlier, I said that elements and attributes don't differ very much, so you might expect that you can address them in the same way, as Listing 3.10 tries to do. </P>
<P>Listing 3.10 Stylesheet Trying to Select Attributes<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Dessert of the Day:<BR>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/desserts/dish[2]/price" /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11: &lt;/xsl:stylesheet&gt;Line 8 in Listing 3.10 tries to get the value of the price attribute of a dish element. That this approach doesn't work is obvious from the result in Listing 3.11.</P>
<P>Listing 3.11 Result from Applying Listing 3.10 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&nbsp;&nbsp; Dessert of the Day:<BR>&nbsp;&nbsp; Chocolat Mousse<BR>&nbsp;&nbsp; Price:The value-of element in Listing 3.10 doesn't yield a result. A gap appears in the result because no element matches the select expression. That is as it should be, because no price element exists. The dish element does, however, have a price attribute, which is what Listing 3.10 is supposed to select. What's wrong?</P>
<P>Nothing is wrong. You just need to tell the processor that it needs to match an attribute, not an element. You can tell the processor that you're looking for an attribute by adding the @ character in front of the name. So, if line 8 in Listing 3.10 is supposed to point to an attribute, the path expression should be /menu/desserts/dish[2]/@price, as shown in Listing 3.12. The result in Listing 3.13 is now correct.</P>
<P>Listing 3.12 Stylesheet Correctly Selecting an Attribute<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Dessert of the Day:<BR>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/desserts/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/desserts/dish[2]/@price" /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11: &lt;/xsl:stylesheet&gt;Listing 3.13 Result from Applying Listing 3.12 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;<BR>&nbsp;&nbsp; Dessert of the Day:<BR>&nbsp;&nbsp; Chocolat Mousse<BR>&nbsp;&nbsp; Price: 5.95Listing 3.12 produces the desired result. Because attributes don't have any child elements, you also know that no side effects will occur. The value of the attribute is always text.</P>
<P>NOTE</P>
<P>Attributes can have data types, but all are based on the text value. Data types will be thoroughly discussed on Day 10, "Working with Data Types."</P>
<P>Because attributes don't have side effects, they are much easier to work with. Also, because all attributes of an element need to have a different name, you have no trouble with matching multiple attributes (and getting only the value of the first). The only way you can get multiple attributes is to start working with selections based on a wildcard character.</P>
<P>Another point to consider is that attributes take less space in a document than elements. Elements have begin and end tags; an attribute doesn't need these tags. Because attributes have only a text value, a parser or processor can deal with them more quickly because it doesn't have to check for child elements. This is likely to have a positive effect on performance.</P>
<P>Beyond the Basics<BR>Until now, the discussion has targeted single nodes wherever possible. In fact, the focus has been on how to avoid selections that yield more than one node. Although this information is very useful to get you started, it really limits your capabilities. Without creating complex expressions, you can already perform many tasks with some of the basic functionality XPath provides.</P>
<P>Using a Wildcard<BR>Wildcard characters are common in most search-oriented functions and languages. XPath has only one wildcard character: *. You can use it only to match entire names of elements or attributes, so the expression a* does not match all elements starting with the letter a. This expression generates an error instead. Wildcards are useful when you want to drill deeper into the source XML, and the names of certain nodes (particularly parent nodes) don't matter. Listing 3.14 shows how to use a wildcard.</P>
<P>Listing 3.14 Stylesheet Using a Wildcard<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/menu/*/dish"&gt;<BR>6:&nbsp;&nbsp; -&lt;xsl:value-of select="text()" /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9: &lt;/xsl:stylesheet&gt;Line 5 in Listing 3.14 uses a wildcard character, so it doesn't matter whether the matched dish element is a child element of the appetizers, entrees, or desserts element. Line 6 just shows the value of the matched dish element. Listing 3.15 shows the result.</P>
<P>Listing 3.15 Result from Applying Listing 3.14 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;</P>
<P><BR>&nbsp;&nbsp; Crab Cakes</P>
<P>&nbsp;&nbsp; Jumbo Prawns</P>
<P>&nbsp;&nbsp; Smoked Salmon and Avocado Quesadilla</P>
<P>&nbsp;&nbsp; Caesar Salad</P>
<P><BR>&nbsp;&nbsp; Grilled Salmon</P>
<P>&nbsp;&nbsp; Seafood Pasta</P>
<P>&nbsp;&nbsp; Linguini al Pesto</P>
<P>&nbsp;&nbsp; Rack of Lamb</P>
<P>&nbsp;&nbsp; Ribs and Wings</P>
<P><BR>&nbsp;&nbsp; Dame Blanche</P>
<P>&nbsp;&nbsp; Chocolat Mousse</P>
<P>&nbsp;&nbsp; Banana SplitIn Listing 3.15, the result yields all the dish nodes, not just those that are child nodes of a particular node.</P>
<P>You can use this technique in all kinds of situations. Say that you've created a whitepaper or book using an XML document. Using a wildcard, you can select all the chapter and section headers to create a table of contents. If you don't want to get all the nodes, using just the wildcard doesn't solve your problem. However, just as with the path expressions you saw earlier, you can use predicates to refine the expression. That way, you have more control over what the wildcard actually matches. A simple example is shown in Listing 3.16.</P>
<P>Listing 3.16 Stylesheet Using Wildcards and Predicates<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;<BR>6:&nbsp;&nbsp; Dessert of the Day:<BR>7:&nbsp;&nbsp; &lt;xsl:value-of select="/menu/*[3]/dish[2]" /&gt;<BR>8:&nbsp;&nbsp; Price: &lt;xsl:value-of select="/menu/*[3]/dish[2]/@*[2]" /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11: &lt;/xsl:stylesheet&gt;Listing 3.16 yields the same result as Listing 3.12; the result is shown in Listing 3.13. Instead of addressing nodes by name, line 8 in Listing 3.16 uses several wildcards aided by position predicates. The desserts element is the third child element of the menu element. The /menu/*[3] section of the path expression tells the processor to take the third child element of the menu element, with no regard to the name of that element. That expression yields the desserts element, just as if it had been named. The attribute chosen is also based on a wildcard. In this case, the expression tells the processor to take the second attribute of the dish element, which is, of course, the price attribute.</P>
<P>Working with the Document Tree<BR>What you've seen so far is quite rigid in utilizing the XML document tree. XPath can do much more, based on location paths, which are expressions that select a node or node-set relative to the context node. A location path consists of several parts. The path expressions you've seen so far often are specific cases of location paths, starting from the root node or current node (from a matching template). Location paths can, however, appear in other instances and as part of a predicate within a path expression. One part of a location path is actually a predicate, so you can have a location path with a predicate, containing a location path containing another predicate, and so on.</P>
<P>Another part of a location path that you are already familiar with is called a node test, which is the part of the location path that matches a certain node or nodes. This definition is clearer with an example. Consider the following location path:</P>
<P>/menu/*[3]/dish[2]/@*[2]Here, menu, *, dish, and @* are node tests.</P>
<P>The last (or actually the first) part of a location path may not be familiar to you yet. This part, called an axis, is an expression specifying the relationship within the document tree between the selected nodes and the context node.</P>
<P>In the previous examples, you saw quite a few location paths. Not all of them contained axes, however. Well, they did, but the axes were included implicitly. Look at the following location path:</P>
<P>/menu/desserts/dishThis location path selects all the dish elements, which are child nodes of desserts nodes, which in turn are child nodes of the root element menu. If you write out that location path in full, it actually reads</P>
<P>/child::menu/child::desserts/child::dishThe axis and the node test are always separated by a double colon. The axis in front of the node test tells the processor where to look for a node or node-set. The node test tells the processor which nodes to actually match. Using the explicit location path isn't very useful for match templates. The location path only becomes lengthier and less readable. Also, you would not often use the child axis because it is included implicitly anyway.</P>
<P>Another axis you are already familiar with is the attribute axis. You are actually familiar with its shortcut, the @ character. In Listing 3.12, the following location path was used on line 8:</P>
<P>/menu/desserts/dish[2]/@priceYou also can write the @price selection using the attribute axis, which would yield the following location path:</P>
<P>/menu/desserts/dish[2]/attribute::priceAn axis that you haven't yet encountered but is quite clear is the parent axis. Yes, you guessed it: It returns the parent node of the current context. Listing 3.17 shows an example using the parent axis.</P>
<P>Listing 3.17 Stylesheet Using parent Axis<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/"&gt;&lt;xsl:apply-templates /&gt;&lt;/xsl:template&gt;<BR>6:<BR>7:&nbsp; &lt;xsl:template match="/menu/appetizers/dish"&gt;<BR>8:&nbsp;&nbsp; &lt;xsl:value-of select="parent::*/@title" /&gt;: &lt;xsl:value-of select="." /&gt;<BR>9:&nbsp; &lt;/xsl:template&gt;<BR>10:<BR>11:&nbsp; &lt;xsl:template match="/menu/entrees" /&gt;<BR>12:&nbsp; &lt;xsl:template match="/menu/desserts" /&gt;<BR>13:<BR>14: &lt;/xsl:stylesheet&gt;Line 8 in Listing 3.17 uses the parent axis to select the title attribute of the parent element. This is the parent element of the current node, which is one of the dish elements in the appetizers element. Listing 3.18 shows the result.</P>
<P>Listing 3.18 Result from Applying Listing 3.17 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;</P>
<P>&nbsp; Work up an Appetite: Crab Cakes<BR>&nbsp; Work up an Appetite: Jumbo Prawns<BR>&nbsp; Work up an Appetite: Smoked Salmon and Avocado Quesadilla<BR>&nbsp; Work up an Appetite: Caesar SaladIn Listing 3.18, the title attribute is inserted with every dish. This could also have been done with absolute addressing, but if there had been a separate template for the dish element, dishes in entrees or desserts could also match and the title would need to be different. In that case, relative addressing using the parent axis would be the only way out.</P>
<P>There is another way to specify any parent node. If you're familiar with the command prompt from DOS or Unix, it will look familiar. The location path</P>
<P>parent::*/@titlecan also be written as</P>
<P><A href="mailto:../@titleThe">../@titleThe</A> latter example is much more compact and usable. If, however, the node test is not a wildcard, using this location path would not work. You would have to specify the parent axis explicitly, as well as the node that the node test needs to match.</P>
<P>Multilevel Axes<BR>The axes discussed so far cover a single level in the XML document tree. They either go one level down, to child nodes, or one level up, to the parent node. Several axes operate on multiple levels. This does not mean, however, that such an axis returns a tree fragment because that wouldn't give added functionality. If that were the case, the parent and child axes would suffice. Each multilevel axis yields a node-set containing all the elements within that axis. The order in which the elements appear in the node-set depends on the axis. So, you can actually think of a multilevel axis as part of the XML document tree "flattened" into a set.</P>
<P>The best way to show you how these axes work is to go through some examples. The easiest axis to start with is ancestor, which is shown in Listing 3.19.</P>
<P>Listing 3.19 Stylesheet Using the Ancestor Axis<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="/menu/appetizers"&gt;<BR>6:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="dish[1]/ancestor::*[1]/@title" /&gt;<BR>7:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="dish[1]/ancestor::menu/entrees/@title" /&gt;<BR>8:&nbsp; &lt;/xsl:template&gt;<BR>9:<BR>10:&nbsp; &lt;xsl:template match="/menu/entrees"&gt;<BR>11:&nbsp; &lt;xsl:template match="/menu/desserts"&gt;<BR>12:<BR>13: &lt;/xsl:stylesheet&gt;All the action occurs in Lines 6 and 7 in Listing 3.19. Both lines first select the first child node of the appetizers element named dish. At that point, this element becomes the context node. Next, the ancestor axis tells the processor it wants to act on the ancestor nodes of the context node. The ancestor nodes are appetizers and menu. On line 6, the node test consists of a wildcard and predicate—in this case, pointing to the first ancestor node in the axis, which is the parent node appetizers. On line 7, a named node test specifies that the menu element is the element needed in this particular axis. This line could also have been written as ancestor::*[2] because that is the grandparent of the context node and, as such, the second node in the axis node-set ancestor.</P>
<P>Listing 3.20 Result from Applying Listing 3.19 to Listing 3.1<BR>&lt;?xml version="1.0" encoding="utf-8"?&gt;</P>
<P>&nbsp;&nbsp;&nbsp; Work up an Appetite<BR>&nbsp;&nbsp;&nbsp; Chow Time!Listing 3.20 shows that Listing 3.19 first selects the title attribute of the appetizers element and then the title attribute of the entrees element.</P>
<P>Several more multilevel axes are available. All axes are listed in Table 3.1.</P>
<P>Table 3.1 Available Axes<BR>Axis<BR>&nbsp;Description<BR>&nbsp;<BR>Self<BR>&nbsp;The context node itself<BR>&nbsp;<BR>child<BR>&nbsp;All child nodes of the context node<BR>&nbsp;<BR>parent<BR>&nbsp;The parent node of the context node<BR>&nbsp;<BR>ancestor<BR>&nbsp;All ancestor nodes of the context node<BR>&nbsp;<BR>ancestor-or-self<BR>&nbsp;Same as ancestor, including the context node as the first node in the node-set<BR>&nbsp;<BR>descendant<BR>&nbsp;All descendant nodes of the context node, numbered depth first (for example, child 1, grandchild 1, child 2, grandchild 2, and so on)<BR>&nbsp;<BR>descendant-or-self<BR>&nbsp;Same as descendant, including the context node as the first node in the node-set<BR>&nbsp;<BR>following-sibling<BR>&nbsp;All sibling nodes that succeed the context node within the document tree<BR>&nbsp;<BR>following<BR>&nbsp;Same as following-sibling, but including their descendants, depth first (for example, sibling 1, child 1 of sibling 1, sibling 2, and so on)<BR>&nbsp;<BR>preceding-sibling<BR>&nbsp;All sibling nodes that precede the context node within the document tree<BR>&nbsp;<BR>preceding<BR>&nbsp;Same as preceding-sibling, but including their descendants, depth first (for example, sibling 1, child 1 of sibling 1, sibling 2, and so on) <BR>&nbsp;</P>
<P><BR>Figure 3.5 shows a graphical representation of most axes in Table 3.1 to give you a better idea of what each axis listed actually selects.</P>
<P>Figure 3.5 Graphical representation of the axes in Table 3.1.</P>
<P>Something that is, strictly speaking, not an axis but fits nicely in this section is the // expression. It matches any location within the document tree. So, //dish matches any dish node within the document. Listing 3.21 shows this expression in action.</P>
<P>Listing 3.21 Stylesheet Using // to Get All Nodes<BR>1: &lt;?xml version="1.0" encoding="UTF-8"?&gt;<BR>2: &lt;xsl:stylesheet version="1.0"<BR>3:&nbsp; xmlns:xsl="<A href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</A>"&gt;<BR>4:<BR>5:&nbsp; &lt;xsl:template match="//dish"&gt;<BR>6:&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="text()" /&gt;<BR>7:&nbsp; &lt;/xsl:template&gt;<BR>8:<BR>9: &lt;/xsl:stylesheet&gt;Listing 3.21 yields the same result as Listing 3.14 because line 5 uses // to match all nodes in the document from which the dish nodes are selected.</P>
<P>A common mistake is to think that //dish[6] will yield the sixth dish element within the document. Unfortunately, because of precedence rules, this expression will yield no element at all. The processor will look for a sixth element in each of the parent contexts. Unfortunately, there is none because appetizers contains only four dish elements; entrees, only five; and desserts, only three. So how do you solve this problem? You can use parentheses to override the default precedence. Therefore, (//dish)[6] would yield the sixth element (the Seafood Pasta).<BR></P>]]></description>
</item><item>
<title><![CDATA[Selecting Data]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40504</link>
<author>xml-linguist</author>
<pubDate>2008/10/8 2:45:18</pubDate>
<description><![CDATA[
<P>Yesterday you learned what a stylesheet is and how to use it. You also learned about using templates and getting values from an Extensible Markup Language (XML) document. So far the expressions you've used to match templates and select data have been rudimentary. What you can do at this point therefore is limited.</P>
<P>Today's lesson will focus on getting more control over the data you select. Today you will learn the following:</P>
<P>How the XML document tree works</P>
<P>What XPath is</P>
<P>How you can select single elements</P>
<P>How you can select multiple elements</P>
<P>How you can select attributes</P>
<P>Understanding the XML Document Tree<BR>An XML document is a hierarchical structure of elements. Each element in an XML document can have zero or more child elements, which in turn have that same property. Also, each element can have zero or more attributes. No surprises so far, but it's actually significant that an XML document is structured this way. Every element and every attribute has a uniquely identifiable place within the document tree. Because all elements and attributes are uniquely identifiable, you can address a single element or attribute and get its value. Figure 3.1 clarifies this structure.</P>
<P>Figure 3.1 Graphical representation of a tree.</P>
<P>In Figure 3.1, each element in the tree is shown as a circle. Different children of an element can be distinguished because different letters identify them. As you can see, some elements have children with the same letters to identify them. This means that you can't say "Give me the value of element C," because element C can be the child element of either element B or element F. This doesn't mean, however, that you can't address this element at all; you just have to be more specific. To get the value of a specific element, you would have to say "Give me the value of element C, the child of element B, which is the child of the root element A." When you address an element in this manner, you use absolute addressing, as shown in Figure 3.1. Absolute addressing means that you specify the exact location of an element within a tree. With absolute addressing, you always specify a unique location.</P>
<P>Another way of addressing is relative to an element. Say that element E in Figure 3.1 is the element's starting point. If you want to address the same element as before, you can say "Give me the value of element C, the sibling element of my parent element." This type of addressing is called relative addressing, as shown in Figure 3.1. Relative addressing means that you specify the location of an element within a tree relative to the position of the current location.</P>
<P>With relative addressing, you don't specify a unique location within the document tree. Which element is specified by the preceding query actually depends on the starting point of the query.</P>
<P>What Is a Node?<BR>Until now, I have been talking about elements and attributes. The difference between elements and attributes is not that great, however. The most important difference is that an element can have child elements; an attribute cannot. Hence, an attribute always has a single (text) value, whereas the value of an element also includes any descendant elements (and attributes).</P>
<P>Because elements and attributes aren't very different, they can be represented as the same thing in a diagram of the XML document tree. Element E in Figure 3.1, for example, could just as well be an attribute because it doesn't have any child elements. In fact, some people think that attributes shouldn't be used because attributes are just special cases of elements. Attributes and elements are interchangeable, as long as an element doesn't have child elements (or attributes). Because attributes are simply names with associated values, also known as name-value pairs, an element can contain only attributes that have different names. An element value, on the other hand, can contain multiple elements with the same name. This distinction is very important when you're designing XML documents, especially when they might have to change in the future.</P>
<P>Within the Document Object Model (DOM), as well as Extensible Stylesheet Language Transformations (XSLT, or actually XPath), the distinction between an element and attribute is so small that they are treated more or less as being the same. Several functions in DOM Level 2 work equally well on elements and attributes. The functions nodeName and nodeValue make no distinction between elements and attributes, although the result may differ based on the type of node the function is used on. Because an element and an attribute are very similar, they are referred to as a node, which is a single item that contains data within the document tree.</P>
<P>Current Node<BR>On Day 2, I used the term current element tentatively. Although this concept is somewhat self-explanatory, some clarification is in order. Also, because of the similarities between elements and attributes, from now on I will use the term current node.</P>
<P>On Day 2, you saw that when a stylesheet processes an XML document, elements of the source XML are matched against templates in the stylesheet. What you haven't learned yet is that you can also create match expressions that match an attribute. So, actually, nodes of the source XML are matched against the templates. Each time a match occurs and a template is invoked, the node that fired the template becomes the current node, which basically is a pointer to a node within the XML tree. This pointer keeps track of which node is being processed.</P>
<P>NOTE</P>
<P>If you're working with an XSLT debugger that enables you to perform the transformation process step by step, you can see which node is the current node. The debugger keeps track of the current node and the template that is being fired and shows that information to you.</P>
<P>Because the current node is just a pointer to the node being processed, a template is not limited to accessing the value of that node alone. Within a template, you can use absolute addressing or relative addressing to get the value of any node in the XML document. As I said earlier, this value isn't necessarily a single value. If an element has attributes and descendant elements, they are also part of that value. Such a value is called a tree fragment, which is a part of an XML document tree, starting at a specific node. A tree fragment is itself a well-formed XML structure or document.</P>
<P>You already saw tree fragments in action on Day 2, when you learned about the text() function that extracts only the text value of an element. If you just specify the value of an element, the text of the element and all its descendants is written to the output. That is, in fact, the text value of the tree fragment. To get a better idea what a tree fragment is, look at Figure 3.2.</P>
<P>Figure 3.2 Tree fragment of node T.</P>
<P>Figure 3.2 is a graphical representation of a tree fragment. In this case, the tree fragment belongs to node T. This is actually the same as the value of node T.</P>
<P>What Is a Node-Set?<BR>Now that you know what a node is, you probably think that a node-set isn't hard to explain. It's a set of nodes, right? Well, yes, but that's not all of it.</P>
<P>When you make a selection based on an expression, the expression doesn't necessarily match one node. It may match several nodes. These nodes together are called a node-set. The most common node-set is a series of an element's child nodes. Some people think this is the only kind of node-set, but it isn't. You can easily create an expression that yields a node-set with nodes in different sections of an XML document. Figure 3.3 shows an example.</P>
<P>Figure 3.3 Node-set containing nodes scattered throughout an XML document.</P>
<P>Figure 3.3 represents the node-set you would get if you were to say "Give me all nodes named B." As you can see, the node's location in the XML document tree is not relevant. Any node matching your query is part of the node-set. The node-set in Figure 3.3 is composed of several nodes. From those nodes, you have access to the tree fragment composed of that node and its descendants. If the expression targeted only attributes, the node-set would consist of only single value nodes.</P>
<P>Node-sets are essential in XSLT. They enable you to create a table of contents, indexes, and all sorts of other documents in which you use data that is scattered throughout an XML document. This capability enables you to create different outputs for different purposes from the same XML source document.</P>]]></description>
</item><item>
<title><![CDATA[人生情怨]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40374</link>
<author>xml-linguist</author>
<pubDate>2008/9/28 23:50:38</pubDate>
<description><![CDATA[
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P align=left><FONT face=楷体_GB2312 size=4>风起云动</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>天地容颜依然</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>时过境迁</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>人生情怀未变</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>有道是</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>山是山</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>川是川</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>山川江河永相连</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>情归情</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>怨归怨</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>情仇恩怨总纠缠</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>谁予我利剑</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>将它斩断</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>一边归情</FONT></P>
<P align=left><FONT face=楷体_GB2312 size=4>一边还怨</FONT></P></BLOCKQUOTE>]]></description>
</item><item>
<title><![CDATA[越学越觉得差远了,不学就根本不知道自己在哪里]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=40365</link>
<author>xml-linguist</author>
<pubDate>2008/9/28 12:40:45</pubDate>
<description><![CDATA[
<P><STRONG>学习xsl的体会</STRONG></P>
<P><STRONG>select="text",&nbsp;select="/*/*/text",&nbsp;select="//text"大不一样<BR></P></STRONG>
<DIV width="100%">
<DIV style="FLOAT: right"><STRONG></STRONG></DIV>
<DIV>不知道大家最初接触这些东西会不会像我一样一知半解. 
<P></P>
<P>我最初以为&lt;xsl:value-of&nbsp;select="text"/&gt;,&nbsp;&lt;xsl:value-of&nbsp;select="/*/*/text"/&gt;,&nbsp;&lt;xsl:value-of&nbsp;select="//text"/&gt;取的值都是text,没有差别.</P>
<P>实际上,这三个text值差别很大:&lt;xsl:value-of&nbsp;select="text"/&gt;只取当前节点下的text值;&nbsp;&lt;xsl:value-of&nbsp;select="/*/*/text"/&gt;取所有含有两个祖元素的text的值,即文档中所有属于第三层的text的值;而&lt;xsl:value-of&nbsp;select="//text"/&gt;所取的值包含文档中所有的text值.</P>
<P>以我的理解,在我这个程度上应用xsl的初学者,大多数所需要的值仅仅是当前节点下的某个元素的值,应该是&lt;xsl:value-of&nbsp;select="text"/&gt;.至于&lt;xsl:value-of&nbsp;select="/*/*/text"/&gt;,&nbsp;&lt;xsl:value-of&nbsp;select="//text"/&gt;,&nbsp;除了做完整的一类数据的分析之外,对于我这个程度的人来说,基本用不着.</P>
<P>越学越觉得差远了,不学就根本不知道自己在哪里!</P></DIV></DIV>]]></description>
</item><item>
<title><![CDATA[哭笑不得]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39459</link>
<author>xml-linguist</author>
<pubDate>2008/9/1 0:52:00</pubDate>
<description><![CDATA[
<P>&nbsp;&nbsp;&nbsp; 竟然有这等事。</P>
<P>&nbsp;&nbsp;&nbsp; 拿到录取通知书，参加了军训，知道了9月1日正式上课，其他的事一概不理：困了就睡，睡醒就玩，饿了就吃。</P>
<P>&nbsp;&nbsp;&nbsp; 算你厉害，给我省了一万，你就这么狂！</P>
<P>&nbsp;&nbsp;&nbsp; 你小子还是嫩着呢！</P>
<P>&nbsp;&nbsp;&nbsp; 直到今天下午才准备明天上学需要的东西，一看录取通知书，才知道8月30号要到校正式办理注册手续，并且旁边有明确的文字说明，即，学校有权对过期不注册者取消入学资格。然后，才给我打电话，问我怎么办？</P>
<P>&nbsp;&nbsp;&nbsp; 能怎么办？你小子能干，明天自己到学校去看！</P>
<P>&nbsp;&nbsp;&nbsp; 真是个宝贝，让人哭笑不得！</P>]]></description>
</item><item>
<title><![CDATA[感悟人生]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39132</link>
<author>xml-linguist</author>
<pubDate>2008/8/21 1:29:26</pubDate>
<description><![CDATA[
<P align=center><FONT face=楷体_GB2312 size=5>（一）</FONT></P>
<P align=center><FONT face=楷体_GB2312 size=5>江河不知清<BR>岸边树倒映<BR>花香何曾羞<BR>只是人多情</FONT></P>
<P align=center><FONT face=楷体_GB2312 size=5>（二）</FONT></P>
<P align=center><FONT face=楷体_GB2312 size=5>人生本无味<BR>山川亦无情<BR>谁若知苦辛<BR>定是执著人<BR></P></FONT>]]></description>
</item><item>
<title><![CDATA[明天的太阳照样升起]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39131</link>
<author>xml-linguist</author>
<pubDate>2008/8/21 1:16:30</pubDate>
<description><![CDATA[
<P>　(2006-06-01日记）</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; 近日的工作颇有麻烦！</P>
<DIV class=item-body>
<DIV class=item-content id=main-content>
<P>　　两年来的苦心操作，至今没有结果！早已敲定的项目无法启动，只能一遍又一遍地核查前期准备工作。尽管到目前为止整个团队还没有出现分崩离析的迹象，人人按时上班，午间休息时照常游戏、聊天，但是，时不时总有一丝令人不安的骚动。</P>
<P>　　小Ｘ这两天请病假了……，小Ｙ说证件被小偷摸了，需要回老家重新办理……</P>
<P>　　我也操心，这是个坎啊！但是，我的心态基本还是稳定的。因为，任何时候，总是有这么一个信念支撑着我，那就是美国作家海明威的一句话－明天的太阳照样升起，这个信念支撑我经历了这么多，尤其是一个个最困难的关头。</P>
<P>　　有一年的夏季乘坐渡轮过琼州海峡。那天刚好是台风天气，本来是取消了的轮班，不知什么原因又开了。尽管有点担心，还是上了船。大概航行一半行程的时候，狂风大作，渡轮开始剧烈地颠簸、大幅度的左右摇晃。从侧窗向外面看，视线时而被大海淹没、时而抛开惊涛骇浪直射天空。我不知道情况有多严重，但随着几个本地渔民装扮的人神色惊慌的呼叫，我意识到情况很不妙了。有几个女人手抓座椅半跪半爬在地上，嘤嘤地哭了起来；很多人开始呕吐，我自知我很快就要撑不住了，但我的意识告诉我必须撑下去。我从靠边的座位慢慢向中间移动，最后在最靠近中心的位置上停了下来。然后，我双手紧紧抓住座椅，把身体尽量固定住，闭上眼睛，什么都不看，任凭渡轮前后颠簸左右摇晃。就这样，一种意念隐隐约约我占据了我整个的思维空间：不管情况多糟，明天的太阳不是照样升起吗？或许我还能看到它呢？</P>
<P>　　大约这样挣扎了将近一个小时，危险过去了……　事后我想到当时的情景，对自己出奇的冷静佩服得五体投地：那么多海边生海边长的人，多数应该会游泳吧，见过的这种场合多了，都惊慌失措的时候，我一个从没有见过这种场面的北方旱鸭子竟然找了在中心位置，定定的坐在那里闭目养神！那么多海里生海里长的人由于船的颠簸摇晃而“呕心沥血”的时候，我一个北方旱地癞蛤蟆居然麻木不仁，硬是连以口唾沫也没有吐出来！我佩服我自己，但更佩服说过“明天的太阳照样升起”的那个人－他真是把一切都看透了！</P>
<P>　　曾经在一家培训机构任职一年，管理一个基本上由富家子弟组成的出国留学培训班。学员问题很多，就不用说了。管理层的人个个名气冲天但办起事来缩手缩脚让人感觉很不舒服。中秋节前大约一个星期，我班学员派代表跟我讨论中秋节的活动事宜，我没有过多考虑就答应他们全班统一搞活动。三五天后，他们每人收费100元，总共凑了大约3000多元，让我带他们外出采购（这个培训机构是封闭型管理）。中秋节前一天，我选了三四个学员一起外出，把需要的东西都买了回来。就在这个时候，问题出现了：培训中心管理层的主管下令中秋节不许搞任何的集体活动，哪个培训班搞，该班的带班老师马上辞退。（听说前一年全中心集体活动过中秋时，由于组织失误，导致场面失控，饮料、月饼、瓜果以及其他食品都成了学员们游戏的武器，整个中心被搞得狼藉一片。管理层的人说起中秋活动谈虎色变。）我的直接上司接到主管的指令之后，匆匆忙忙找我了解情况，问我是不是已经有了具体安排。我向来与这个办事萎萎缩缩的全国名教（他好像有一个全国什么什么教师的称号，教学上可以说是一把好手，但做起管理来，真是无法让人恭维）胃口不同，很不喜欢他的办事方式。他给我这个班也上课，这几天来的情况他应该很清楚。我告诉他已经安排好了，到时候会邀请各位任教老师都参加的。他说我应该给中心提前汇报一下，我说我不能越级汇报，给你汇报就行了……这样，这件事被桶到了管理最高层。</P>
<P>　　中秋节早上课程结束以后，我班学员问我答应的事是否还要办下去。他们已经知道中心不允许搞活动，现在就看我如何答复了。我告诉他们一切照常，大家下午开始准备活动，活动内容以“中秋赏月”为主题，布置教室时可以在黑板上点名主题（当地中秋有一种活动，类似于集资抽奖，用管理方的话说是赌博。用3000多元钱买东西剩余的部分搞这个项目，我不能明确答应，只能通过明确活动主题的方式向上级敷衍－不管怎么说，也该给高层一点面子嘛！）。下午的时候，我打发几个学员，把请帖发给所有的任课教员和教务部门……（所有任课老师以及其他受邀请的人一个也没有来。）</P>
<P>　　下午三点多，该发生的事发生了！中心主管在教务主任（就那个全国名教）的陪同下，来我班亲自过问了！</P>
<P>　　首先，我得过关！我承认是我同意学员办的！我说知道禁令的时候已经刹不住车了。我说我没有提前向李教务汇报过！这种简单的节庆，任何机构任何人随时都搞，没必要向谁汇报！我说我现在不能按照禁令办，我只能做到对学员信守诺言，否则，即使保住工作，学员们会造反的，我还是干不下去。</P>
<P>　　主管要亲自给学生做工作了。于是，我向主管和教务告辞了！</P>
<P>　　回到宿舍，心情颇不平静。泡杯茶，点支烟，冷静一下。不经意间，一切都轻松了：管他三七二十一，明天的太阳照样升起！迷迷糊糊中，我听见有人敲门。一看表，是晚饭时间了，还没有到明天的太阳升起的时候，会有什么事呢？<BR>　　<BR>　　我的班长来找我，说他们把主管跟教务给摆平了，现在需要我去给担保学员不会出乱子。我爽快的答应了。可想而知，在以后的半年里，我都成了这一班学员的英雄了。</P>
<P>　　……</P>
<P>　　目前的境况是有点难！</P>
<P>　　我是不是需要好好睡一觉，然后看看明天会升起一轮什么样的太阳！</P></DIV></DIV>]]></description>
</item><item>
<title><![CDATA[城里的亲戚]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39084</link>
<author>xml-linguist</author>
<pubDate>2008/8/19 11:31:46</pubDate>
<description><![CDATA[
<P>&nbsp;&nbsp;&nbsp; 话说乡里老汉拉着毛驴进巩昌城赶集。赶完集从市场出来到鼓楼十字。路过毛家烧鸡摊，老汉寻思，进一趟城不容易，到跟前了就吃一碗。于是就把驴栓到旁边的电线杆上，打开料袋让驴自个儿吃料，随着一声“一碗烧鸡粉，加个蛋”就在烧鸡摊的小凳子上坐下。不一会，烧鸡粉加鸡蛋端上了小桌子，老汉唏溜唏溜地吃了起来。</P>
<P></P>&nbsp;&nbsp;&nbsp; 当时，有几个小青年也在烧鸡摊上边喝酒边吃烧鸡。听见老汉唏溜唏溜的声音，嫌老汉土气，想捉弄老汉一番。 
<P></P>&nbsp;&nbsp;&nbsp;&nbsp;“吃啥好东西，呵楞楞地（形容声响很大），香得很！” 
<P></P>&nbsp;&nbsp;&nbsp;&nbsp; 老汉听见有人说话，以为是在说自己，忙笑呵呵地答话：“没啥好吃的，就吃一碗烧鸡粉！” 
<P></P>
<P>&nbsp;&nbsp;&nbsp; “驴还吃烧鸡粉哩！”一个小青年指着栓在电线杆上的驴说，其他的几个一阵狂笑。</P>
<P>&nbsp;&nbsp;&nbsp; 老汉一句话也没有说，连喝带吃几大口把烧鸡粉吃完，付过钱，朝毛驴走去。</P>
<P>&nbsp;&nbsp;&nbsp; 突然，只听“啪！啪！”两声。烧鸡摊上的人顺着声音的方向看过去。只见老汉朝着毛驴的长脸又一次左右开弓，嘴里骂骂咧咧：“进城前我问过你城里有没有亲戚，你说没有！你说，给你打招呼的是你的啥亲戚？”</P>
<P>&nbsp;</P>
<P></P>
<P>（注：最早听朋友的朋友讲起这个笑话。后来我把这个笑话推荐给朋友的朋友，便出现在了他的博客中。近日重温，倍感风趣，把它再搬过来。）</P>]]></description>
</item><item>
<title><![CDATA[梦回陇西]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39054</link>
<author>xml-linguist</author>
<pubDate>2008/8/18 10:59:44</pubDate>
<description><![CDATA[
<P align=center><STRONG><FONT face=楷体_GB2312 size=5>终日有所思，</FONT></STRONG></P>
<P align=center><STRONG><FONT face=楷体_GB2312 size=5>梦里回陇西。</FONT></STRONG></P>
<P align=center><STRONG><FONT face=楷体_GB2312 size=5>窗外雪花飘，</FONT></STRONG></P>
<P align=center><STRONG><FONT face=楷体_GB2312 size=5>炉边茶香溢。</FONT></STRONG></P>
<P>&nbsp;</P>
<P><FONT face=仿宋_GB2312 size=4>（三年前听到老先生仙逝的消息，想起当年与老先生雪天炉边焙茗之情景，是夜梦游陇西，重温那段忘年之交。次日心生感慨而作。老先生三年忌日即将来临之际，谨以此文为祭。）</FONT></P>]]></description>
</item><item>
<title><![CDATA[云里雾里一支烟]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39019</link>
<author>xml-linguist</author>
<pubDate>2008/8/17 0:02:59</pubDate>
<description><![CDATA[
<P>&nbsp;&nbsp;&nbsp; 这几天思绪混乱，做东西进展不大。时而苦想，时而游戏，苦乐参半。倒是这种状态让我感觉到自己可以掌握大局即可，没有必要花太多是时间做永远也不得要领的这些事。盯着一个文件看，开始时思路听清楚的，做着做着就犯糊涂了，大脑一片混沌，本来条例清楚的文档，突然变得云里雾里，把人看得颠三倒四－这不是我要的结果。</P>
<P>&nbsp;&nbsp;&nbsp; 其实，知道了大概的原理，该转换一下角色了。即使我把毕生的精力都花在这方面，不一定能做出一个令人满意的东西。我的主要目的就是通过学习了解一下规划与执行之间有多大的出入，不是直接参与其中。是该找人做的时候了。我再这么做下去，无异于浪费时间。</P>
<P>&nbsp;&nbsp;&nbsp; 来杯茶，抽支烟，下盘棋。然后轻轻松松的睡觉。</P>]]></description>
</item><item>
<title><![CDATA[拼搏与时机]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=xml-linguist&amp;id=39018</link>
<author>xml-linguist</author>
<pubDate>2008/8/16 23:36:55</pubDate>
<description><![CDATA[
<P>&nbsp;&nbsp;&nbsp; 身体不适，本想早睡。无奈看了刚刚结束的奥运羽球男双决赛，心中闷得慌，不得不发泄一下。</P>
<P>&nbsp;&nbsp;&nbsp; 三局两胜的比赛，中国对第一局赢得轻松，想必第二局不会有太大的问题吧。谁知我看到的时候第二局已经是中国队已经落后对手六七分，而对手已经离局点仅有两三分了。</P>
<P>&nbsp;&nbsp;&nbsp; 谁都有过这样的境遇：已经胜过对方一筹，何必过多在乎此筹？尽力吧！再胜一筹当然好，即使输了，不过才是个平手吗？</P>
<P>&nbsp;&nbsp;&nbsp; 这正是要命的错误。我们一生中的很多失败就是由这种心理导致的。不拼此筹，气势上已经输了。即使再给你一个机会，你也不一定能取胜于对手。</P>
<P>&nbsp;&nbsp;&nbsp; 中国队轻易放弃本可以再拼一番的第二局，这是一个严重的错误。如果第二局就使劲拼，谁也说不清会不会有咸鸭翻身的机会。一旦有，那就是终结对手。即使让对手拿下，也让他们心理上发怵。第二局落后时的拼和第三局落后的时候的拼，效果截然不同：前者是在要对手的命，后者只是再和对手争胜负。</P>
<P>&nbsp;&nbsp;&nbsp; 拼搏是人生的主题曲。有些人唱得好，只是因为唱对了时机。错过了时机，无论如何拼搏，多半是徒劳的。</P>]]></description>
</item>
</channel>
</rss>