﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-编程之道-随笔分类-web编程</title><link>http://www.cppblog.com/ispfcn/category/1305.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 24 May 2008 20:54:47 GMT</lastBuildDate><pubDate>Sat, 24 May 2008 20:54:47 GMT</pubDate><ttl>60</ttl><item><title>在PHP中实现进程间通讯</title><link>http://www.cppblog.com/ispfcn/archive/2008/04/18/47518.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Fri, 18 Apr 2008 09:26:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2008/04/18/47518.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/47518.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2008/04/18/47518.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/47518.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/47518.html</trackback:ping><description><![CDATA[<p>　　本文将讨论在PHP4环境下如何使用进程间通讯机制——IPC(Inter-Process-Communication)。本文讨论的软件环境是Linux+php4.0.4或更高版本。首先,我们假设你已经装好了PHP4和UNIX, 为了使得php4可以使用共享内存和信号量，必须在编译php4程序时激活shmop和sysvsem这两个扩展模块。 </p>
<p>　　实现方法：在PHP设定(configure)时加入如下选项。 <br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">enable</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">shmop&nbsp;</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">enable</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">sysvsem&nbsp;&nbsp;</span></div>
<p>&nbsp;</p>
<p>　　这样就使得你的PHP系统可以处理相关的IPC函数了。 </p>
<p>　　IPC是什么？ </p>
<p>　　IPC (Inter-process communication) 是一个Unix标准通讯机制，它提供了使得在同一台主机不同进程之间可以互相通讯的方法。基本的IPC处理机制有3种：它们分别是共享内存、信号量和消息队列。本文中我们主要讨论共享内存和信号量的使用。关于消息队列，笔者在不久的将来还会专门介绍。 </p>
<p>　　在PHP中使用共享内存段 </p>
<p>　　在不同的处理进程之间使用共享内存是一个实现不同进程之间相互通讯的好方法。如果你在一个进程中向所共享的内存写入一段信息，那么所有其他的进程也可以看到这段被写入的数据。非常方便。在PHP中有了共享内存的帮助，你可以实现不同进程在运行同一段PHP脚本时返回不同的结果。或实现对PHP同时运行数量的实时查询等等。 </p>
<p>　　共享内存允许两个或者多个进程共享一给定的存储区。因为数据不需要在客户机和服务器之间复制，所以这是最快的一种IPC。使用共享内存的唯一窍门是多个进程对一给定存储区的同步存取。 </p>
<p>　　如何建立一个共享内存段呢？下面的代码可以帮你建立共享内存。&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #800080">$shm_id</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;shmop_open(</span><span style="COLOR: #800080">$key</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$mode</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$perm</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$size</span><span style="COLOR: #000000">);&nbsp;</span></div>
<p>&nbsp;</p>
<p>　　注意，每个共享内存段都有一个唯一的ID, 在PHP中，shmop_open会把建立好的共享内存段的ID返回，这里我们用$shm_id记录它。而$key是一个我们逻辑上表示共享内存段的Key值。不同进程只要选择同一个Key id就可以共享同一段存储段。习惯上我们用一个串（类似文件名一样的东西）的散列值作为key id. $mode指明了共享内存段的使用方式。这里由于是新建，因此值为&#8217;c&#8217; &#8211;取create之意。如果你是访问已经建立过的共享内存那么请用&#8217;a&#8217;,-- 取Access之意。$perm参数定义了访问的权限，8进制，关于权限定义请看UNIX文件系统帮助。$size定义了共享内存的大小。尽管有点象fopen(文件处理)你可不要当它同文件处理一样。后面的描述你将看到着一点。 </p>
<p>　　例如： <br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #800080">$shm_id</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;shmop_open(</span><span style="COLOR: #000000">0xff3</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0644</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);&nbsp;</span></div>
<p><br>　　这里我们打开了一个共享内存段 键值0xff3 &#8211;rw-r—r—格式，大小为100字节。 </p>
<p>　　如果需要访问已有的共享内存段，你必须在调用shmop_open中设第3、4个参数为0。 </p>
<p>　　IPC工作状态的查询 </p>
<p>　　在Unix下，你可以用一个命令行程序ipcs查询系统所有的IPC资源状态。不过有些系统要求需要超级用户方能执行。下图是一段ipcs的运行结果。</p>
<p>&nbsp;<img height=159 alt="" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/1.jpg" width=400 border=0><br>　　上图中系统显示了4个共享内存段，注意其中第4个键值为0x00000ff3的就是我们刚刚运行过的PHP程序所创建的。关于ipcs的用法请参考UNIX用户手册。 </p>
<p>　　如何释放共享内存呢 </p>
<p>　　释放共享内存的办法是调用PHP指令:shmop_delete($id) </p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">shmop_delete(</span><span style="COLOR: #800080">$id</span><span style="COLOR: #000000">);&nbsp;</span></div>
<p>&nbsp;</p>
<p>　　$id 就是你调用shmop_open所存的shmop_op的返回值。还有一个办法就是用UNIX的管理指令: </p>
<p>　　ipcrm id, id就是你用ipcs看到的ID.和你程序中的$id不一样。不过要小心，如果你用ipcrm直接删除共享内存段那么有可能导致其他不知道这一情况的进程在引用这个已经不复存在的共享内存器时出现一些不可预测的错误(往往结果不妙)。 </p>
<p>　　如何使用(读写)共享内存呢 </p>
<p>　　使用如下所示函数向共享内存写入数据 </p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">int&nbsp;shmop_write&nbsp;(int&nbsp;shmid</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;data</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;int&nbsp;offset)&nbsp;</span></div>
<p>&nbsp;</p>
<p>　　其中shmid是用shmop_open返回的句柄。$Data变量存放了要存放的数据。$offset描述了写入从共享内存的开始第一个字节的位置（以0开始）。 </p>
<p>　　读取操作是： </p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">&nbsp;shmop_read&nbsp;(int&nbsp;shmid</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;int&nbsp;start</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;int&nbsp;</span><span style="COLOR: #008080">count</span><span style="COLOR: #000000">)&nbsp;</span></div>
<p>&nbsp;</p>
<p>　　同样，指明$shmid,开始偏移量（以0开始）、总读取数量。返回结果串。这样，你就可以把共享内存段当作是一个字节数组。读几个再写几个，想干嘛就干嘛，十分方便。 </p>
<p>　　多进程问题的考虑 </p>
<p>　　现在，在单独的一个PHP进程中读写、创建、删除共享内存方面上你应该没有问题了。但是，显然实际运行中不可能只是一个PHP进程在运行中。如果在多个进程的情况下你还是沿用单个进程的处理方法，你一定会碰到问题 ---- 著名的并行和互斥问题。比如说有2个进程同时需要对同一段内存进行读写。当两个进程同时执行写入操作时，你将得到一个错误的数据，因为该段内存将之可能是最后执行的进程的内容，甚至是由2个进程写入的数据轮流随机出现的一段混合的四不象。这显然是不能接受的。为了解决这个问题，我们必须引入互斥机制。互斥机制在很多操作系统的教材上都有专门讲述，这里不多重复。实现互斥机制的最简单办法就是使用信号灯。信号量是另外一种进程间通讯(IPC)的方式，它同其他IPC机构(管道、FIFO、消息队列)不同。它是一个记数器，用于控制多进程对共享数据的存储。同样的是你可以用ipcs和ipcrm实现对信号灯使用状态的查询和对其实现删除操作。在PHP中你可以用下列函数创建一个新的信号量并返回操作该信号量的句柄。如果该key指向的信号量已经存在，sem_get直接返回操作该信号量的句柄。 </p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">int&nbsp;sem_get&nbsp;(int&nbsp;</span><span style="COLOR: #008080">key</span><span style="COLOR: #000000">&nbsp;[</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;int&nbsp;max_acquire&nbsp;[</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;int&nbsp;perm]])&nbsp;</span></div>
<p>&nbsp;</p>
<p>　　$max_acquire 指明同时最多可以用几个进程进入该信号而不必等待该信号被释放（也就是最大同时处理某一资源的进程数目,一般该值均为一）。$perm指明了访问权限。 </p>
<p>　　一旦你成功的拥有了一个信号量，你对它所能做的只有2种：请求、释放。当你执行释放操作时, 系统将把该信号值减一。如果小于0那就还设为0。而当你执行请求操作时，系统将把该信号值加一，如果该值大于设定的最大值那么系统将挂起你的处理进程直到其他进程释放到小于最大值为止。一般情况下最大值设为1,这样一来当一个进程获得请求时其他后面的进程只能等待它退出互斥区后释放信号量才能进入该互斥区并同时设为独占方式。这样的信号量常称为双态信号量。当然，如果初值是任意一个正数就表明有多少个共享资源单位可供共享应用。 </p>
<p>　　申请、释放操作的PHP格式如下： </p>
<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">int&nbsp;sem_acquire&nbsp;(int&nbsp;sem_identifier)&nbsp;</span></div>
<p><br>申请 <br><br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">int&nbsp;sem_release&nbsp;(int&nbsp;sem_identifier)&nbsp;</span></div>
<p><br>释放 <br>其中sem_identifier是调用sem_get的返回值（句柄）。&nbsp; <br>一个简单的互斥协议例子 <br>下面是一段很简单的互斥操作规程。 <br></p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #800080">$semid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">sem_get(</span><span style="COLOR: #000000">0xee3</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">0666</span><span style="COLOR: #000000">);&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #800080">$shm_id</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;shmop_open(</span><span style="COLOR: #000000">0xff3</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">c</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0644</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">100</span><span style="COLOR: #000000">);&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>sem_acquire(</span><span style="COLOR: #800080">$semid</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">申请&nbsp;</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>/*</span><span style="COLOR: #008000">&nbsp;进入临界区</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">这里，对共享内存进行处理&nbsp;</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>sem_release(</span><span style="COLOR: #800080">$semid</span><span style="COLOR: #000000">);&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">释放&nbsp;</span></div>
<p>&nbsp;</p>
<p>&#160;</p>
<p>　　正如你所看到的，互斥的实现很简单：申请进入临界区，对临界区资源进行操作（比如修改共享内存）退出临界区并释放信号。这样一来就可以保证在同一个时间片中不可能有同时2个进程对同一段共享内存进行操作。因为信号量机制保证一个时间片只能由一个进程进入，其他进程必须等待当前处理的进程完成后方能进入。 </p>
<p>　　临界区一般是指那些不允许同时有多个进程并发处理的代码段。 </p>
<p>　　要注意的是:在PHP中必须由同一个进程释放它所占用的信号量。在一般系统中允许进程释放别的进程占用的信号。在编写临界区代码一定要小心设计资源的分配，避免A等B，B等A的死锁情况发生。&nbsp;</p>
<p>　　<strong>运用</strong> </p>
<p>　　IPC的运用是十分广泛的。比如，在不同进程间保存一个解释过的复杂的配置文件、或具体设置的用户等，以避免重复处理。我也曾经用共享内存的技术把一大批PHP脚本必须引用的一个很大的文件放入共享内存，并由此显著提升了Web服务的速度、消除了部分瓶颈。关于它的使用还有聊天室，多路广播等等。IPC的威力取决于你的想象力的大小。如果本文对你有一点点启发，那我不胜荣幸。愿意很你讨论这令人入迷的电脑技术。Email: qwyaxm@163.net </p>
<p><br><br>&nbsp;</p>
<img src ="http://www.cppblog.com/ispfcn/aggbug/47518.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2008-04-18 17:26 <a href="http://www.cppblog.com/ispfcn/archive/2008/04/18/47518.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Apache模块 开发实例(转)</title><link>http://www.cppblog.com/ispfcn/archive/2008/01/30/42234.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Wed, 30 Jan 2008 08:35:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2008/01/30/42234.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/42234.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2008/01/30/42234.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/42234.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/42234.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;&nbsp;1/**//**&nbsp;&nbsp;2*&nbsp;Copyright&nbsp;2003&nbsp;Tom,&nbsp;Inc.&nbsp;All&nbsp;rights&nbsp;reserved.&nbsp;&nbsp;3*&nbsp;&nbsp;4*&nbsp;Description:&nbsp;Apache模块&nbsp;取用户图片&nbsp;...&nbsp;&nbsp;<a href='http://www.cppblog.com/ispfcn/archive/2008/01/30/42234.html'>阅读全文</a><img src ="http://www.cppblog.com/ispfcn/aggbug/42234.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2008-01-30 16:35 <a href="http://www.cppblog.com/ispfcn/archive/2008/01/30/42234.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Smarty截取中文扩展，支持UTF-8和GB</title><link>http://www.cppblog.com/ispfcn/archive/2007/11/20/37010.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Tue, 20 Nov 2007 06:34:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2007/11/20/37010.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/37010.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2007/11/20/37010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/37010.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/37010.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000">&nbsp;smarty_modifier_truncate_cn(</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">80</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$code</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$etc</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/dot.gif"></span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{<br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;(</span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$code</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">){<br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$pa</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #800080">$pa</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">/[\x01-\x7f]|[\xa1-\xff][\xa1-\xff]/</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}<br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008080">preg_match_all</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$pa</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$string</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$t_string</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #008080">count</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$t_string</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">])&nbsp;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">join</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">array_slice</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$t_string</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">))</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$etc</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">join</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #008080">array_slice</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$t_string</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #800080">$length</span><span style="COLOR: #000000">));<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>}</span></div>
<br>以下代码保存为ascii格式<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">html</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">head</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">title</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">Truncate&nbsp;测试</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">title</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">meta&nbsp;</span><span style="COLOR: #ff0000">http-equiv</span><span style="COLOR: #0000ff">="Content-Type"</span><span style="COLOR: #ff0000">&nbsp;content</span><span style="COLOR: #0000ff">="text/html;&nbsp;charset=gbk"</span><span style="COLOR: #ff0000">&nbsp;</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">head</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">body</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{{$string}}</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">br</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{{$string|truncate_cn:15:"":""}}</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">br</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">body</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">html</span><span style="COLOR: #0000ff">&gt;</span></div>
<br><br>以下代码保存为:UTF-8格式<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">&nbsp;1</span><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">html</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">head</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">title</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">Truncate&nbsp;测试</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">title</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">meta&nbsp;</span><span style="COLOR: #ff0000">http-equiv</span><span style="COLOR: #0000ff">="Content-Type"</span><span style="COLOR: #ff0000">&nbsp;content</span><span style="COLOR: #0000ff">="text/html;&nbsp;charset=UTF-8"</span><span style="COLOR: #ff0000">&nbsp;</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">head</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">body</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{{$string}}</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">br</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>{{$string|truncate_cn:15:"UTF-8":"<img src="http://www.cppblog.com/Images/dot.gif">"}}</span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">br</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">&nbsp;9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">body</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">html</span><span style="COLOR: #0000ff">&gt;</span></div>
<br>
<img src ="http://www.cppblog.com/ispfcn/aggbug/37010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2007-11-20 14:34 <a href="http://www.cppblog.com/ispfcn/archive/2007/11/20/37010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>抓取腾讯天气预报的类</title><link>http://www.cppblog.com/ispfcn/archive/2007/08/27/30940.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Mon, 27 Aug 2007 08:37:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2007/08/27/30940.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/30940.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2007/08/27/30940.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/30940.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/30940.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 类的代码：&nbsp;&nbsp;1&lt;?php&nbsp;&nbsp;2/**&nbsp;&nbsp;3&nbsp;*&nbsp;抓取腾讯天气，存储成XML&nbsp;&nbsp;4&nbsp;*&nbsp;@author&nbsp;PeterPan&nbsp;&nbsp;5&nbsp;*&nbsp;@final&nbsp;2007-08-27&nbsp;&nbsp;6&nbsp;*/&...&nbsp;&nbsp;<a href='http://www.cppblog.com/ispfcn/archive/2007/08/27/30940.html'>阅读全文</a><img src ="http://www.cppblog.com/ispfcn/aggbug/30940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2007-08-27 16:37 <a href="http://www.cppblog.com/ispfcn/archive/2007/08/27/30940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（九）——XSL函数二</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12449.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 03:20:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12449.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12449.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12449.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12449.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12449.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<p>　　本期介绍多个XSL对于VBScript、JScript增加的方法、属性，以充分发挥XML的优势，用于&lt;xsl:script&gt;、&lt;xsl:eval&gt;标记内表达式的编写或&lt;xsl:if&gt;、&lt;xsl:when&gt;的expr属性。</p>
		<p>
		</p>
		<p>　　一、absoluteChildNumber </p>
		<p>　　含义：返回结点相对于它所有的兄弟（不论名字是否相同）的序号。</p>
		<p>　　语法：absoluteChildNumber(node)</p>
		<p>　　参数：node ── 对象，欲返回编号的结点。</p>
		<p>　　示例：</p>
		<p>　　1、假定文档结构为：&lt;document&gt;&lt;head/&gt;&lt;body/&gt;&lt;/document&gt;，其中document为顶层结点，下述表达式将输出：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">xsl:eval</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />absoluteChildNumber(this.selectNodes('/document/body').item(0))<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">xsl:eval</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>　　2、确定当前结点相对于其所有兄弟的序号：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />absoluteChildNumber(this)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span></div><p>　　二、ancestorChildNumber</p><p>　　含义：从给定结点出发根据给定祖先结点名返回最近的祖先结点的序号（相对于同名结点）。如果找不祖先，则返回0。</p><p>　　语法：ancestorChildNumber(bstrNodeName, pNode)</p><p>　　参数：</p><p>　　bstrNodeName ── 字符串。被搜索的祖先结点的名字。</p><p>　　pNode ── 对象。搜索开始位置的结点。</p><p>　　示例查找当前结点最近的名为report祖先结点：</p><p>ancestorChildNumber('report',this)</p><p>　　三、attributes</p><p>　　含义：返回结点属性的集合。</p><p>　　语法：object.attributes</p><p>　　参数：object ── 结点对象。</p><p>　　示例：当前结点属性的个数</p><p>this.attributes.length</p><p>　　当前结点第三个属性的值</p><p>this.attributs.item(2).value</p><p>或<br /><br />this.attributes.item(2).text</p><p>或<br /><br />this.attributes(2).text</p><p>　　注意：如果给定的下标大于属性总和减1将出错，第一个属性的下标是0。</p><p>　　四、baseName</p><p>　　含义：返回有名字空间限制的基本名，即不包括名字前缀。</p><p>　　语法：object.baseName</p><p>　　参数：object ── 结点对象</p><p>　　示例，当前结点的基本名：<br /><br />this.baseName</p><p>　　五、childNumber</p><p>　　含义：返回结点相对于同名同胞的序号。</p><p>　　语法：childNumber(object)</p><p>　　参数：object ── 结点对象</p><p>　　示例，假定XML文档结构如下：</p><p>&lt;x&gt;&lt;y&gt;&lt;z&gt;&lt;/z&gt;&lt;/y&gt;&lt;/x&gt;</p><p>　　如果当前结点是z，则childNumber(this)返回1，而absoluteChildNumber(this)返回3。 </p><p>　　六、dataType</p><p>　　含义：设定或读取结点的数据类型。</p><p>　　语法：设定结点的数据类型 object.dataType=objValue<br />　　　　　读取结点的数据类型 objValue=object.dataType</p><p>　　参数：object ── 结点对象。<br /><br />　　示例，读取当前结点的数据类型：</p><p>dtType=this.dataType</p><p>　　七、depth</p><p>　　含义：指定结点出现在文档树上的深度，即该结点位于文档第几层，顶层结点位于第一层，根结点（即用"/"表示的结点）位于第0层。</p><p>　　语法：depth(pNode)</p><p>　　参数：pNode ── 结点对象</p><p>　　示例，当前结点的深度：</p><p>depth(this)</p><p>　　八、firstChild、lastChild</p><p>　　含义：返回结点的第一个子结点（或最后一个子结点）。</p><p>　　语法：pNode.firstChild<br />　　　　　pNode.lastChild</p><p>　　参数：pNode ── 结点对象</p><p>　　示例，当前结点的第一个结点的名字：</p><p>this.firstChild.nodeName</p><p>　　九、formatIndex</p><p>　　含义：用指定的计数系统格式化提供的整数。</p><p>　　语法：formatIndex(lIndex, bstrFormat)</p><p>　　参数：</p><p>　　lIndex ── 整型数值或变量</p><p>　　bstrFormat ── 数据格式，可选值有a、A、i、I、1、01（以0打头的数值形式，如果要求固定长度的编号如0001、0002则非常有用）。</p><p>　　示例，当前结点的大写罗马数字编号：</p><p>formatIndex(childNumber(this),'I')</p><p>　　十、formatNumber</p><p>　　含义：以指定格式输出数值。</p><p>　　语法：formatNumber(dblNumber, bstrFormat)</p><p>　　参数：说明同formatNumber，不同之处在于格式化的可以是小数。</p><p>　　示例，对变量a的值格式化为两位小数：<br /><br />formatNumber(a,'#.00')：</p><p>　　十一、hasChildNodes</p><p>　　含义：如果结点有子结点则返回true（-1），否则为false（0）。</p><p>　　语法：pNode.hasChildNodes()</p><p>　　注意：与此前介绍的函数不同，此函数后必须带一个空括号。</p><p>　　示例，判断当前结点是否有子结点：</p><p>this.hasChildNodes</p><p>　　十二、namespaceURI、prefix</p><p>　　含义：返回结点名字空间的全局资源标识符（或前缀）。</p><p>　　语法：pNode.namespaceURI<br />　　　　　pNode.prifix</p><p>　　十三、nextSibling、previousSibling、parentNode</p><p>　　含义：返回结点的下一个兄弟（或前一个兄弟、或结点的父结点）。</p><p>　　语法：pNode.nextSibling<br />　　　　　pNode.previousSibling<br />　　　　　pNode.parentNode</p><p>　　注意：对根结点（即"/"）应用parentNode方法、对第一个孩子结点应用previousSibling方法、对最后一个孩子结点应用nextSibling方法均会导致错误，可通过此过关系运算符==（等于）和!=（不等于）来判断一个结点是否某一指定结点，格式为pNode1 = pNode2或pNode2 != pNode2。</p><p>　　十四、nodeName</p><p>　　含义：返回元素、属性、入口的名字或其他类型结点的一个特定字符串。</p><p>　　语法：pNode.nodeName</p><p>　　示例，当前结点的名字：</p><p>this.nodeName</p><p>　　十五、nodeType、NodeTypeString</p><p>　　含义：返回结点的类型的数值形式（或字符串形式）。<br /><br />　　语法：pNode.nodeType 或 pNode.nodeTypeString</p><p>　　返回值：<br /><img height="186" alt="o_xsl_12.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_12.JPG" width="503" border="0" /><br /></p><p>　　十六、nodeTypedValue</p><p>　　含义：以结点预定义的数据类型返回结点的值。</p><p>　　语法：pNode.nodeTypedValue</p><p>　　示例，假定当前结点的数据类型是fixed.14.4，下例将以数值返回结点的值，而不是文本一个字符串：</p><p>this.nodeTypedValue</p><p>　　十七、nodeValue</p><p>　　含义：返回结点的文本。</p><p>　　语法：pNode.nodeValue</p><p>　　注意：该方法不用于元素类结点，可用于属性、CDATA、注释、文本等结点。</p><p>　　示例，当前元素第一个属性的值：</p><p>this.attributes(0).nodeValue</p><p>　　当前元素内的文本（假定该元素内只有文本，无其它元素，即&lt;mark&gt;text&lt;/mark&gt;，建议多尝几次掌握其确切的用法）。</p><p>this.firstChild.nodeValue</p><p>　　十八、ownerDocument</p><p>　　含义：返回包含该结点的文档的根。</p><p>　　语法：pNode.ownerDocument</p><p>　　注意：该方法用于文档的根结点将出错。</p><p>　　十九、selectNodes</p><p>　　含义：给定的样式匹配应用于当前结点并返回匹配的结点集合。</p><p>　　语法：pNode.selectNodes('pattern')</p><p>　　提示：pattern的编写与&lt;xsl:for-each&gt;的select属性的值类似，其中以"/"开头表示从文档的根出发搜索；以"//"开头表遍历文档的所有结点；以".."开头表示从当前结点的父结点开始；如果欲从当前结点向下搜索则不能有以上特殊字符打头。</p><p>　　示例，与当前结点同名的元素在其父元素内的个数：</p><p>childNumber(this.selectNodes("../"+this.nodeName+"[end()]").item(0))</p><p>　　当前元素内名字为"skill"的元素的个数：</p><p>childNumber(this.selectNodes("skill[end()]").item(0))</p><p>　　二十、selectSingleNode</p><p>　　含义：与selectNodes类似，不同的只返回匹配的第一个结点、而不是结点集合。</p><p>　　语法：pNode.selectSingleNode('pattern')</p><p>　　示例，与当前结点同名的元素在其父元素内的个数：</p><p>childNumber(this.selectSingleNode("../"+this.nodeName+"[end()]"))</p><p>　　当前元素内名字为"skill"的元素的个数：</p><p>childNumber(this.selectSingleNode("skill[end()]"))</p><p>　　二十一、text</p><p>　　含义：返回结点与它的子树内的文字内容。</p><p>　　语法：pNode.text</p><p>　　示例，整个文档内的文字内容：</p><p>this.ownerDocument.text</p><p>　　当前元素及其子树的文字内容：</p><p>this.text</p><p>　　二十二、xml</p><p>　　含义：返回结点及其后代的XML表示。</p><p>　　语法：pNode.xml</p><p>　　示例，当前文档的XML内容：</p><p>this.ownerDocument.xml</p><p>　　另有几个函数不作介绍，列于其下以供参考，如感兴趣，请访问http://msdn.microsoft.com获取详细说明。</p><p>formatTime(varTime, bstrFormat,varDestLocale) <br />formatDate(varDate, bstrFormat,varDestLocale)<br />apendChild(newChild)<br />definition<br />CloneNode<br />insertBefore(newChild, refChild)<br />parsed<br />removeChild(oldChild)<br />replaceChild(newChild, oldChild)<br />specified<br />transformNode(stylesheet)<br />transformNodeToObject(stylesheet,outputObject) <br />uniqueID(pNode) </p><img src ="http://www.cppblog.com/ispfcn/aggbug/12449.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 11:20 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12449.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（八）——脚本与XSL的结合及应用</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12448.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 03:17:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12448.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12448.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12448.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12448.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12448.html</trackback:ping><description><![CDATA[　有时，我们可能会希望XML文档输出时能对其中内容加上一些统计信息或者如编号什么的，利用前面的知识就不太容易实现了。今天将介绍两个新元素&lt;xsl:eval&gt;与&lt;xsl:script&gt;，使我们能轻松处理这个难题。
<p>&lt;xsl:eval&gt;</p><p>　　含义：计算脚本表达式，输出一个文本字符串。</p><p>　　语法：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:eval </span><span style="COLOR: #ff0000">language</span><span style="COLOR: #0000ff">="language-name"</span><span style="COLOR: #0000ff">&gt;</span></div><p>　　属性：</p><p>　　language ── 规定所用脚本语言的名字，可用的属性有"JavaScript"、"JScript"、"VBScript"、"VBS"等，缺省为"JScript"。</p><p>&lt;xsl:script&gt;</p><p>　　含义：声明全局变量或定义函数。</p><p>　　语法：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:script </span><span style="COLOR: #ff0000">language</span><span style="COLOR: #0000ff">="language-name"</span><span style="COLOR: #0000ff">&gt;</span></div><p>　　属性：同&lt;xsl:eval&gt;</p><p><br />　　示例：</p><p>　　不知大家对于第四期《跟我学XML》中的例子是否还有印象？其中的XML文档并没有对简历编号，但输出中却加上了大写的罗马数字序号。今天将再举一稍为复杂一些的例子：</p><p>　　假如我们编写一份年终生产统计表，其中需要小计一项，常规的作法是事先将其算出来，现在不必了，我们可以只给出单项统计，显示时再统计小计一项。请找出《跟我学XML》的第四期，XML文件不必修改，对XSL文件的修改如下：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:stylesheet </span><span style="COLOR: #ff0000">xmlns:xsl</span><span style="COLOR: #0000ff">="http://www.w3.org/TR/WD-xsl"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="/"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1999年生产统计</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="document"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="document"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">H3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1999年生产统计</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">H3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">班组</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">一季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">二季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">三季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">四季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="report"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">小计</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">total(this,"q1")</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">total(this,"q2")</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">total(this,"q3")</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">total(this,"q4")</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:script</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />function total(node,q)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　temp=0; <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　mark='/document/report/'+q;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　v=node.selectNodes(mark);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　for(t=v.nextNode();t;t=v.nextNode())<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　　　temp+=Number(t.text);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />　　return temp; //小计值<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:script</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="report"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="class"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q1"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q2"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q3"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q4"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="q1|q2|q3|q4"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">此处测试产量，如小于等于20则添加一STYLE属性color，其值为red（红色）</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:if </span><span style="COLOR: #ff0000">test</span><span style="COLOR: #0000ff">=".[value() $le$ 20]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:attribute </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="style"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">color:red</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:attribute</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:if</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:stylesheet</span><span style="COLOR: #0000ff">&gt;</span></div><img height="192" alt="r_xsl_13.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/r_xsl_13.JPG" width="272" border="0" /><br /><p>　　说明：</p><p>　　注意到执行结果的变化了吗？黑体部分为添加部分，注意添加部分分为两部分，&lt;xsl:script&gt;&lt;/xsl:script&gt;必须置于&lt;/TABLE&gt;之后，切记。</p><p>　　selectNodes() ── 是XMLDOMObject的一个方法，返回文档中所有满足条件的结点的集合，条件与&lt; xsl:for-each &gt;和select属性的取值采用同样的写法，可以加筛选、下标等限制，如寻找一季度产量大于等于50的班组：</p><p>/document/report/q1[value() $ge$ 50]</p><p>　　以上写法还有一个更简单的写法：</p><p>//q1[value()$ge$50]</p><p>　　//表示从根结点出发遍历所有结点，寻找满足条件的结点，如果文档内有同名但意义不同的结点则不能用此种方法，非不得已不建议使用。以此为例，如果希望统计年总产量，则可以下述字符串寻找结点（建议使用最后一种，此种描述将精确找到需要汇总的数据）：</p><p>//*[value()$gt$0] 或 //(q1|q2|q3|q4) 或 /document/report/(q1|q2|q3|q4)</p><p>　　nextNode() ── 返回结点集中的下一个结点</p><p>　　Number() ── 将提供的参数转换为数值</p><p><br />　　下期介绍XSL函数2，用于&lt;xsl:script&gt;及&lt;xsl:eval&gt;中，以及&lt;xsl:if&gt;和&lt;xsl:when&gt;的expr属性。建议读者熟悉JavaScript、JScript、VBScript中至少一种，否你能用XSL完成的工作将十分有限。由于篇幅关系，此处不作详细介绍。</p><img src ="http://www.cppblog.com/ispfcn/aggbug/12448.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 11:17 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12448.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（七）——XSL函数一</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12447.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 03:15:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12447.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12447.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12447.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12447.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12447.html</trackback:ping><description><![CDATA[　　本期学习XSL样式方法，即可用于XSL元素&lt;xsl:for-each&gt;、&lt;xsl:value-of&gt;、&lt;xsl:template&gt;的select属性、&lt;xsl:apply-templates&gt;的match属性、&lt;xsl:if&gt;、&lt;xsl:when&gt;的test属性中，对元素的范围进行筛选，从而提供更大的灵活性。 
<p><br />　　XML与DHTML（动态HTML）一样，这些节点都是一个个对象，而且这些对象都是有层次的，从根节点开始构成一颗层次清淅的树状结构，这就形成了文档对象模型DOM(Document Object Model)，通过对象的属性、方法来达到访问控制XML节点的目的。</p><p><br />　　我们这里不打算就XML的DOM逐一详细阐述，因为这完全可以写成一个篇幅较多的教程，我们先就一些常见的方法作一些讨论，以期对DOM的对象方法有一个大致的了解。</p><p>　　注：从本期开始，所有示例不再提供完整源代码，如有不明白之处，请仔细阅读前面七期、并动手练手。</p><p>　　一、end()</p><p>　　含义：返回集合中最后一个元素。</p><p>　　示例：输出最后一份简历</p><p>　　假定XML文件格式为：</p><p>……&lt;resume&gt;…&lt;/resume&gt;……&lt;resume&gt;…&lt;/resume&gt;……</p><p>　　相应XSL文件内容为：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="resume[end()]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">……</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span></div>　　或：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:templates </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="resume[end()]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">……</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:templates</span><span style="COLOR: #0000ff">&gt;</span></div>　　或：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-template </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="resume[end()]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">……</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:apply-template</span><span style="COLOR: #0000ff">&gt;</span></div><p>　　二、index()</p><p>　　含义：返回该元素在集合中的位置，返回值是一整数，其中第一个元素返回0。</p><p>　　示例：返回前面三份简历。</p><p>resume[index()$le$3]</p><p>　　注意：index()是与父元素相关的，请看下例：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">x</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">y</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">y</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">x</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">x</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">y</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">y</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">x</span><span style="COLOR: #0000ff">&gt;</span></div><br /><p>　　返回所有&lt;x&gt;中的第一个&lt;y&gt;</p><p>x/y[index()=0] 或x/y[0]</p><p>　　三、nodeName()</p><p>　　含义：返回元素的名字，即标记名。</p><p>　　示例：选择任意元素，假如其名字（即标记名）等于"name"：</p><p>*[nodeName()='name'] 或 *[name]</p><p>　　四、number()</p><p>　　含义：将值转换为数值形式，如果不是数值则返回空，要求参数。</p><p>　　示例：年龄(age)小于30岁的人的简历(resume)：</p><p>resume[number(age)$lt$30] 或 resume[age$lt$30]</p><p>　　五、nodeType()</p><p>　　含义：返回结点类型，结果为是数值。以下是返回值列表：<br /><img height="186" alt="r_xsl_12.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/r_xsl_12.JPG" width="503" border="0" /><br /></p><p>　　六、value()</p><p>　　含义：返回元素或属性的值。</p><p>　　示例：value()是元素或属性的缺省方法，以下表示是等价：</p><p>name!value()="NAME" 与 name="NAME"<br /><br />@attr="attribute_value" 与 @attr="attribute_value"</p><p>　　注：@是属性前缀，@attr表示是属性attr</p><p>　　七、attribute()</p><p>　　含义：返回所有属性结点的集合，等价于"@*"。</p><p>　　示例：寻找所有的resume元素，满足条件至少有一个属性的值为"ABC"：</p><p>resume[$any$attribute()='ABC'] 或 resume[$any$@*='ABC']</p><p>　　寻找所有的resume元素，满足条件至少有一个子元素有一个属性的值为"ABC"：</p><p>resume[$any$*/attribute()='ABC'] 或 resume[$any$*/@*='ABC']</p><p>　　八、comment()</p><p>　　含义：返回所有注释结点。</p><p>　　示例：</p><p>resume[$any$comment()='禹希初的简历']</p><p>　　表示寻找含有注释语句：&lt;!--禹希初的简历--&gt;的&lt;resume&gt;元素。</p><p>　　九、cdata()</p><p>　　含义：返回所有CDATA类型的结点的集合。</p><p>　　示例：</p><p>resume[$any$cdata()='禹希初的简历']</p><p>　　表示寻找含有下述语句（必须是直接子结点）&lt;![CDATA[禹希初的简历]]&gt;的&lt;resume&gt;元素。</p><p>　　十、node()</p><p>　　含义：返回当前上下文环境中除根结点和属性结点以外的所有结点的集合，等价于：</p><p>"*|pi()|comment()|text()"</p><p>　　示例：寻找所有元素resume，其最后一个结点的名字为"skill"：</p><p>resume[node()[end()]!nodeName()='skill']</p><p>　　寻找所有resume元素的第一个结点：resume/node()[0]。</p><p>　　十一、textnode()</p><p>　　含义：返回所有文本类型的结点的集合。</p><p>　　示例：寻找每一个p元素的第二个文本结点：</p><p>p/textnode(1) 或 p!textnode(1)</p><p>　　十二、text()</p><p>　　含义：返回所有表示文本字符串的结点的集合，等价于"cdata()|textnode()"。</p><p>　　本期的内容就介绍至此，另有一个函数date()在本人的机器上一试就发生错误使浏览器自动关闭，还有一个函数pi()本人尚未找到适当的应用方法，就不介绍了，下期将讲述如何XSL中使用脚本。</p><img src ="http://www.cppblog.com/ispfcn/aggbug/12447.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 11:15 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12447.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（六）——XSL的运算符</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12446.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 03:11:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12446.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12446.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12446.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12446.html</trackback:ping><description><![CDATA[
		<p>表一、运算符与特殊字符<br /><img height="413" alt="o_xsl_9.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_9.JPG" width="500" border="0" /><br /><br />表二、逻辑运算符<br /><img height="101" alt="r_xsl_10.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/r_xsl_10.JPG" width="506" border="0" /><br /><br />表三、关系运算符<br /><img height="398" alt="r_xsl_11.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/r_xsl_11.JPG" width="504" border="0" /><br /></p>
		<p>　　示例一：</p>
		<p>　　从个人简历中寻找具有具有"WEB开发"技能的人的姓名与E-Mail。假设文档结构如下所示：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">document</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">resume</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">name</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">sex</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">sex</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">sex</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">birthday</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">birthday</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">birthday</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">skill1</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">skill2</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">skill2</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />…<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">skilln</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">resume</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">resume</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />…<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">resume</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />…<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">document</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>　　为从以上结构的个人简历中寻找出所有具有WEB开发"技能的人的姓名与E-Mail的XSL文档结构如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">姓名</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">E-Mail</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="resume [$any$skill="</span><span style="COLOR: #ff0000">WEB开发"]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="E-Mail"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span></div><p>　　说明：</p><p>　　1.[ ] ── 表示选择条件，只有满足条件的个人简历才被显示。</p><p>　　2.$any$ ── 由于每个人有多种技能，故加$any$作为前缀，以使每个人所有技能都能被比较。</p><p>　　3.skill='WEB开发' ── 筛选条件。</p><p>　　示例二、</p><p>　　仍上面的XML文档为例，如果欲选择1977/1/1之前出生的人的姓名、技能与E-Mail，相应的XSL文档结构如下（假定生日格式为yyyy/mm/dd）：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">姓名</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">技能</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">E-Mail</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="resume[birthday$lt$"</span><span style="COLOR: #ff0000">1977/1/1"]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="skill[0]"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="skill[index()&gt;0]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">、<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="."</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="E-Mail"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span></div><br /><p>　　说明：</p><p>　　1.birthday $lt$ '1977/1/1' ── 搜索条件，在此处使用"&lt; "会错误，故使用"$lt$"表示小于。</p><p>　　2.skill [0] ── 表示选择skill的第一项。</p><p>　　3.skill [index()&gt;0] ── 表示选择skill的第二项以后（包括第二项）的项目。</p><p>　　4.xsl:value-of select="." ── 表示选择当前标记的值。</p><p>　　相信大家应该注意到，在前面以及本次的例子中出现了一些函数，如index()、formatIndex()、childNumber()，也许大家还不完全明了其中的含义吧？敬请关注下一课。</p><img src ="http://www.cppblog.com/ispfcn/aggbug/12446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 11:11 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（五）——XSL中的choose</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12443.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 03:05:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12443.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12443.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12443.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12443.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12443.html</trackback:ping><description><![CDATA[
		<p>　　上期我们学习了XSL元素&lt;xsl:if&gt;，已能通过测试XML数据的值来决定不同的输出形式，不知你尝试过没有，实际上&lt;xsl:for-each&gt;也可部分实现&lt;xsl:if&gt;的功能，但有时，我们希望对同一数据同时测试多个条件，根据不同条件输出相应结果。当然，我们可以用if，假如我们只有if可用的话。幸好我们有一个更好的选择，那就是用&lt;xsl:choose&gt;。下面介绍相关元素的语法：<br /><br />　　&lt;xsl:choose&gt;<br /><br />　　语法：&lt;xsl:choose&gt;<br /><br />　　属性：无，表示一个多选测试的开始</p>
		<p>　　&lt;xsl:when&gt;<br /><br />　　语法：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">xsl:when </span>
				<span style="COLOR: #ff0000">expr</span>
				<span style="COLOR: #0000ff">="script-expression"</span>
				<span style="COLOR: #ff0000"> language</span>
				<span style="COLOR: #0000ff">="language-name"</span>
				<span style="COLOR: #ff0000"> test</span>
				<span style="COLOR: #0000ff">="pattern"</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>　　属性：<br /><br />　　expr ── 脚本语言表达式，计算结果为"真"或"假"；如果结果为"真"，且通过test，则在输出中显示其中内容（可省略此项属性）。<br /><br />　　language ── expr属性中表达式的脚本语言类型，其取值与HTML标记SCRIPT的LANGUAGE属性的取值相同，缺省为"JScript"。<br /><br />　　test ── 源数据测试条件。
<p>　　&lt;xsl:otherwise&gt;<br /><br />　　语法：&lt;xsl:otherwise&gt;<br /><br />　　属性：无，在一个多选测试中，如果没有不满足&lt;xsl:when&gt;规定的条件，如果在最后有此标记，则输出此标记中的内容。</p><p>　　示例：</p><p>　　此处以学生成绩单为例，要求按成绩的高低给出优秀（ &gt;85）、一般（70~85）、及格（60~69）、不及格（&lt; 60），而不是显示分数。其中成绩单的XML文档(文件名：grade.xml)如下：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml-stylesheet type="text/xsl" href="grade.xsl"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">document</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">grade</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">大胖</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">english</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">80</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">english</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">math</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">90</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">math</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">chymest</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">90</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">chymest</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">grade</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">grade</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">小花</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">english</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">98</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">english</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">math</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">70</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">math</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">chymest</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">85</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">chymest</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">grade</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">document</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br /><p>　　为实现按分数分等级显示，其XSL文档（文件名：grade.xsl）内容如下：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:stylesheet </span><span style="COLOR: #ff0000">xmlns:xsl</span><span style="COLOR: #0000ff">="http://www.w3.org/TR/WD-xsl"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="/"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">成绩单</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="document"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="document"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">姓名</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">英语</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">数学</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">化学</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="grade"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="grade"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="english"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="math"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="chymest"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="english|math|chymest"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:choose</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:when </span><span style="COLOR: #ff0000">test</span><span style="COLOR: #0000ff">=".[value()$gt$85]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">优秀</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:when</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:when </span><span style="COLOR: #ff0000">test</span><span style="COLOR: #0000ff">=".[value()$gt$70]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">一般</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:when</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:when </span><span style="COLOR: #ff0000">test</span><span style="COLOR: #0000ff">=".[value()$gt$60]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">起格</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:when</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:otherwise</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">不起格</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:otherwise</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:choose</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:stylesheet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br /><img height="123" alt="o_xsl_8.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_8.JPG" width="267" border="0" /><br />　说明：在&lt;xsl:choose&gt;选择中，从第一个&lt;xsl:when&gt;开始，逐个测试，直到满足一个测试条件就将其中的内容输出，不再测试后面的条件；如果不满足任何一个条件，则输出&lt;xsl:otherwise&gt;中的内容。<br /><br />　　标记对&lt;xsl:when&gt;&lt;/xsl:when&gt;与&lt;xsl:otherwise&gt;&lt;/xsl:otherwise&gt;中可嵌套&lt;xsl:if&gt;或&lt;xsl:choose&gt;。<img src ="http://www.cppblog.com/ispfcn/aggbug/12443.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 11:05 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12443.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（四）——测试模式</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12441.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 03:02:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12441.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12441.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12441.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12441.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12441.html</trackback:ping><description><![CDATA[
		<p>　　XML技术的优势之一就在于数据输出的可选择性，即选择需要的数据输出。前面我们所讲到的选择模式语句:&lt;xsl:for-each&gt;、&lt;xsl:value-of&gt;及&lt;xsl:apply-template&gt;只是简单的选取通过"/"符号层层到达的节点，如果我们对XML数据不需要全部输出，而只需要其中的满足某条件的部分数据，"萝卜青菜、各取所需"，那么条件判断&lt;xsl:if&gt;与多条件判断&lt;xsl:choose&gt;及&lt;xsl:when&gt;则迎合了这种需要，如果你对程序设计熟悉的话，会觉得它们似曾相识。 </p>
		<p>
		</p>
		<p>　　XSL中的IF，首先，介绍XSL元素&lt;xsl:if&gt;的语法结构： </p>
		<p>
		</p>
		<p>　　语法：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">xsl:if </span>
				<span style="COLOR: #ff0000">expr</span>
				<span style="COLOR: #0000ff">="script-expression"</span>
				<span style="COLOR: #ff0000"> language</span>
				<span style="COLOR: #0000ff">="language-name"</span>
				<span style="COLOR: #ff0000"> test</span>
				<span style="COLOR: #0000ff">="pattern"</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>　属性：
<p>　　expr ── 脚本语言表达式，计算结果为"真"或"假"；如果结果为"真"，且通过test，则在输出中显示其中内容（可省略此项属性）。 </p><p>　　language ── expr属性中表达式的脚本语言类型，其取值与HTML标记SCRIPT的LANGUAGE属性的取值相同，缺省为"JScript"。<br /><br />　　test ──源数据测试条件。 </p><p>　　示例： </p><p>　　此处以一份报表为例，文件名为report.xml，其内容如下： <br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml-stylesheet type="text/xsl" href="report.xsl"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">document</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">report</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />甲班<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q1</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">50</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q1</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q2</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">70</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q2</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">30</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q4</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q4</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">report</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">report</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />乙班<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q1</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">20</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q1</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q2</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">30</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q2</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">40</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q4</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">50</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q4</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">report</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">report</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />丙班<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q1</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">70</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q1</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q2</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">40</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q2</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">20</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">q4</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">10</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">q4</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">report</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">document</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> </span></div><br />　　我们采用XSL模板结合今天所学的&lt;xsl:if&gt;，为其编写一个XSL文档，要求季度产量小于等于20的用红色表示，文件名为report.xsl，内容如下： <br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:stylesheet </span><span style="COLOR: #ff0000">xmlns:xsl</span><span style="COLOR: #0000ff">="http://www.w3.org/TR/WD-xsl"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="/"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1999年生产统计</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="document"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="document"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">H3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1999年生产统计</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">H3</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">班组</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">一季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">二季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">三季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">四季度</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="report"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="report"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="class"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q1"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q2"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q3"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="q4"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="q1|q2|q3|q4"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">此处测试产量，如小于等于20则添加一STYLE属性color，其值为red（红色）</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:if </span><span style="COLOR: #ff0000">test</span><span style="COLOR: #0000ff">=".[value()$le$20]"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:attribute </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="style"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">color:red</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:attribute</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:if</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:stylesheet</span><span style="COLOR: #0000ff">&gt;</span></div><img height="176" alt="o_xsl_7.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_7.JPG" width="272" border="0" /><br /><p>　　说明：</p><p>　　q1|q2|q3|q4 ──　标记q1、q2、q3、q3均用此模板确定输出</p><p>　　$le$ ──　是关系运算符中的"小于等于"，其它关系有小于（$lt$）、大于（$gt$）、大于等于（$ge$）、等于（$eq$）、不等于（$ne$）等。</p><p>　　. ──　表示引用当前标记。</p><p>　　[ ] ──　表示筛选，只有满足筛选条件的标记才能被选取。</p><p></p><p>　　value() ──XSL函数，其他常用XSL函数有text()、end()、index()等。 </p><p></p><p></p><p>　　下期，我们将学习XSL的另外三个元素，可对同一数据进行多次测试，根据不同条件产生相应输出。</p><img src ="http://www.cppblog.com/ispfcn/aggbug/12441.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 11:02 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12441.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（三）——XSL模板与匹配模式</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12440.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 02:56:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12440.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12440.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12440.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12440.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12440.html</trackback:ping><description><![CDATA[
		<p>　　经过前几日的学习，我们学习了XHTML文档的编写和以及三个XSL元素，已能编写相当灵活的XSL文档，今天将学习的是XSL模板的编写。我们都知道，短的文档、程序十分好读，但当规模增大后，其复杂性也以更快的速度增加。</p>
		<p>　　前面我们学了&lt;xsl:for-each&gt;、&lt;xsl:value-of&gt;等，可以用它们对XML数据实现简单的格式化输出，但如果遇到比较复杂的XML格式输出，将XSL按照要求依次写下来的话，一是设计困难，可扩展性差，不利于人员之间的分工协作；另则，可修改性很差，可能会出现牵一发而动全军的情况，不利于维护。程序中模块化设计逐步细化的方法在这里得到了应用！ </p>
		<p>　　XSL模板将XSL的设计细化成一个个模板（块），最后再将这些模板（块）组合成一个完整的XSL；好比船与集装箱，我们不是将所有的货物一件件地堆起来，而是装在各自的集装箱中，然后再在船上将这些集装箱堆放起来。这种方法可以使你先从整体上考虑整个XSL的设计，然后将一些表现形式细化成不同的模块，再具体设计这些模块，最后将它们整合在一起，这样，将宏观与微观结合起来，符合人们条理化、规范化要求。</p>
		<p>
		</p>
		<p>　　装集装箱－－书写模板（块）：&lt;xsl:template&gt;</p>
		<p>　　语法：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">xsl:template </span>
				<span style="COLOR: #ff0000">match</span>
				<span style="COLOR: #0000ff">="node-context"</span>
				<span style="COLOR: #ff0000"> language</span>
				<span style="COLOR: #0000ff">="language-name"</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>　属性：
<p>　　match ── 确定什么样的情况下执行此模板。作为一种简化的说明，在此处使用标记的名字；其中最上层模板必须将match设为"/"。</p><p>　　language ── 确定在此模板中执行什么脚本语言，其取值与HTML中的SCRIPT标记的LANGUAGE属性的取值相同，缺省值是Jscript。</p><p>　　&lt;xsl:template&gt;用match属性从XML选取满足条件的节点，征对这些特定的节点形成一个特定输出形式的模板。</p><p></p><p>　　吊集装箱上船－－调用模板（块）：&lt;xsl:apply-templates&gt;</p><p>　　语法：</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="pattern"</span><span style="COLOR: #ff0000"> order-by</span><span style="COLOR: #0000ff">="sort-criteria-list"</span><span style="COLOR: #0000ff">&gt;</span></div><p>属性：</p><p>　　select ── 确定在此上下文环境中应执行什么模板，即选取用&lt; xsl:template &gt;标记建立的模板（块）。</p><p>　　order-by ── 以分号（;）分隔的排序标准，通常是子标记的序列。</p><p>　　示例：</p><p>　　以个人简历为例，为便于处理我们希望"技能"中每一项都用标记对&lt;skill&gt;&lt;/skill&gt;括起来，有多少项技能就有多少个这种标记对，经过修改后的个人简历XML文档内容如下：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml-stylesheet type="text/xsl" href="resume_template.xsl"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">document</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">resume</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">禹希初</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">sex</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">男</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">sex</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">birthday</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">1977.5</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">birthday</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">skill</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">数据库设计与维护</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">skill</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">skill</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">WEB开发</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">skill</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">resume</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">document</span><span style="COLOR: #0000ff">&gt;</span></div><br />　　然后，建立一个新XSL文件resume_template.xsl，采用模板的形式，其内容如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:stylesheet </span><span style="COLOR: #ff0000">xmlns:xsl</span><span style="COLOR: #0000ff">="http://www.w3.org/TR/WD-xsl"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">根模板</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="/"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">个人简历</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="document/resume"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">简历模板</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="resume"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">CAPTION</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">个人简历（<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">formatIndex(childNumber(this),"I")</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:eval</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />）</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">CAPTION</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="sex"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="birthday"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">技能</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD </span><span style="COLOR: #ff0000">COLSPAN</span><span style="COLOR: #0000ff">="5"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:apply-templates </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="skill"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">BR</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">姓名模板</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">姓名</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">性别模板</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="sex"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">性别</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">生日模板</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="birthday"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">生日</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">技能模板</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:template </span><span style="COLOR: #ff0000">match</span><span style="COLOR: #0000ff">="skill"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:template</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:stylesheet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><img height="139" alt="o_xsl_6.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_6.JPG" width="259" border="0" /><br />　　保存文件，打开文件（个人简历.xml），效果令人满意吧。其实要做到同样的效果，用前面三周介绍的方法也可做，但你得把它作为一整体考虑。<br /><br />　　在上面的XSL文件中，我们将性别、生日、技能等数据项分别用模板来单独写，再用&lt;xsl:apply-template&gt;来调用，这样，即使你日后要对这些模板作相应的修改与扩充也很方便，不致于出现互相干扰、混杂不清的情况。这种从上至下、逐层细化的设计方法，极大地减少工作复杂程度，也大大减少了差错的产生，可以实现多人的协作设计。 
<p>　　注意：如果XML文档中不同标记有同名的子标记，在为其编写模板时，应把父标记作为其前缀，格式为（parent_mark/child_mark）。模板文件必须有一个根模板，其属性match是"/"。</p><img src ="http://www.cppblog.com/ispfcn/aggbug/12440.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 10:56 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12440.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（二）——XSL入门</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12439.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 02:52:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12439.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12439.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12439.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12439.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12439.html</trackback:ping><description><![CDATA[　上期我们讲到用CSS（层叠样式表）来格式化XML文档，其效果并不很令人满意。实际上CSS用来格式化HTML标记比较合适些，只是因为它简单才在上例中采用。<br /><br />　　XML在更多的时候只是一种数据文件，怎样将它变为我们日常所看到的HTML格式那样的文件呢？如果我们将XML文件比作结构化的原料的话，那么XSL就好像"筛子"与"模子"，筛子选取自己需要的原料，这些原料再通过模子形成最终的产品：HTML。<br /><br />　　这个模子大致是这样：我们先设计好表现的页面，再将其中需要从XML中获取数据来填充内容的部分"挖掉"，然后用XSL语句从XML中筛出相关的数据来填充。一言以譬之：这XSL实际上就是HTML的一个"壳子"，XML数据利用这个"壳"来生成"传统"的HTML。<br /><br />　　XML在展开时是一个树形结构，我们将树形结构中自定义标记称为节点，节点之间存在父子、兄弟关系，我们要访问其中的结点从根结点就要以"／"来层层进入。<br /><br />　　在XSL这个壳中，我们要从原料库XML里提取相关的数据，就要用到XSL提供的模式化查询语言。所谓模式化查询语言，就是通过相关的模式匹配规则表达式从XML里提取数据的特定语句，即我们上面所说的"筛子"。
<p>　　参考微软的"XSL开发者指南"，我们大致可将模式语言分为三种：</p><p>　　选择模式：<br /><br />&lt;xsl:for-each&gt;、&lt;xsl:value-of&gt;和 &lt;xsl:apply-templates&gt;</p><p>　　测试模式：<br /><br />&lt;xsl:if&gt; 和&lt;xsl:when&gt;</p><p>　　匹配模式：<br /><br />&lt;xsl:template&gt;<br /><br />　　我们现在就分别对之进行介绍。<br /><br />　　一、 选择模式<br /><br />　　选择模式语句将数据从XML中提取出来，是一种简单获得数据的方法，这几个标记都有一个select属性，选取XML中特定的结点名的数据。<br /><br />　　<b>1、&lt;xsl:for-each&gt;</b><br /><br />　　如在XML中有这样的数据:<br /><br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">author</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">小禹</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">春华</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">秋实</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">author</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><br />　我们要读取这三个作者名字，是一个一个地按"author/name"方法来读取吗，可有多个这样的name呀？如果有一种程序性的语句来循环读取有多好啊！<br /><br />　　想得很对，XSL提供了这样的具有程序语言性质的语句：&lt;xsl:for-each&gt;<br /><br />　　用它读取这三个作者名字的方法如下:<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="author/name"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />……<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span></div>　　select，顾名思义，选取，它可以选定XML中特定唯一的标记，也可以选择某一类相同的标记，我们称之为结点集。<br /><br />　　语法：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="pattern"</span><span style="COLOR: #ff0000"> order-by</span><span style="COLOR: #0000ff">="sort-criteria-list"</span><span style="COLOR: #0000ff">&gt;</span></div>　　属性：<br /><br />　　1.select<br /><br />　　根据XSL样式查询考察上下文以决定哪类结点集（满足select条件）使用此样式描述。作为一种简化的表示就是，如果你想对文档中的某一种标记的内容的显示方式进行格式化，就可以将让select等于此元素的标记名。例如欲对标记xml_mark进行格式化，即可用如下方式表示：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="xml_mark"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">样式定义</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span></div>　　2.order-by<br /><br />　　以分号（;）分隔、作为排序标准的列表。在列表元素前添加加号（+）表示按此标记的内容以升序排序，添加减号（-）表示逆序排序。作为一种简化的表示就是，排序标准列表就是由select规定的标记的子标记的序列，每个标记之间以（;）分隔。
<p>　　<b>2、&lt;xsl:value-of&gt;</b><br /><br />　　&lt;xsl:for-each&gt;模式只是选取节点，并没有取出节点的值，好比猴子只是爬到了树的某个枝干上，那么就用&lt; xsl:value-of &gt;来摘"胜利果实"吧！<br /><br />　　语法：<br /><br />&lt;xsl:value-of select="pattern"&gt;提取节点的值<br /><br />　　属性：<br /><br />　　select用来与当前上下文匹配的XSL式样。简单的讲，如果要在XSL文档某处插入某个XML标记（假定是xml_mark标记）的内容，可用如下方式表示：<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="xml_mark"</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">xsl:value-of</span><span style="COLOR: #0000ff">&gt;</span></div><br />　　或<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="xml_mark"</span><span style="COLOR: #0000ff">/&gt;</span></div>示例：<br /><br />　　此处仍以上期的个人简历的作为例子，我们需要对文件（个人简历.xml）作一定修改，确切的说是将其中的第二行：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml-stylesheet type="text/css" href="resume.css"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div>　　修改为：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml-stylesheet type="text/xsl" href="resume.xsl"</span><span style="COLOR: #0000ff">?&gt;</span></div>　然后建立一个新文件：resume.xsl，其内容如下：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;?</span><span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span><span style="COLOR: #0000ff">?&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HTML </span><span style="COLOR: #ff0000">xmlns:xsl</span><span style="COLOR: #0000ff">="http://www.w3.org/TR/WD-xsl"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">个人简历</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TITLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">HEAD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">xsl:for-each </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="resume"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">P</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TABLE </span><span style="COLOR: #ff0000">border</span><span style="COLOR: #0000ff">="1"</span><span style="COLOR: #ff0000"> cellspacing</span><span style="COLOR: #0000ff">="0"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">CAPTION </span><span style="COLOR: #ff0000">style</span><span style="COLOR: #0000ff">="font-size: 150%; font-weight: bold"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />个人简历<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">CAPTION</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">姓名</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="name"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">性别</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="sex"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">生日</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="birthday"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">技能</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TH</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">TD </span><span style="COLOR: #ff0000">colspan</span><span style="COLOR: #0000ff">="5"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">xsl:value-of </span><span style="COLOR: #ff0000">select</span><span style="COLOR: #0000ff">="skill"</span><span style="COLOR: #0000ff">/&gt;&lt;/</span><span style="COLOR: #800000">TD</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TR</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">TABLE</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">xsl:for-each</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">BODY</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">HTML</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span></div><img height="115" alt="o_xsl_4.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_4.JPG" width="267" border="0" /><br />　　完成这些以后再来让我们看一下辛勤劳动的成果，怎么样？效果不错吧。更酷还在后头呢。现在我们对文件（个人简历.xml）作进一步的修改：<br /><br />　　1.在标记&lt;resume&gt;前添加一个新标记&lt;document&gt;；<br /><br />　　2.将标记对&lt;resume&gt;&lt;/resume&gt;之间的内容（包括这一对标记）复制并粘贴在其后，并在最后用&lt;document&gt;结束。<br /><br />　　3.以Notepad.exe打开文件resume.xsl，在标记&lt;HTML&gt;之后添加文字：&lt;xsl:for-each select="document"&gt;；在标记&lt;/HTML&gt;之前添加文字：&lt;/xsl:for-each&gt;，保存文件。<br /><br />　　4.在浏览器中打开文件（个人简历.xml）。看到了什么？两份个人简历！<br /><img height="217" alt="o_xsl_5.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_5.JPG" width="282" border="0" /><br />　　就这样，利用XML我们可以编写内容与样式完成分离的文档！当然，XSL文件比一般的HTML文件要复杂一些，然而一旦完成则可用于格式化所有同类的XML文档。 <img src ="http://www.cppblog.com/ispfcn/aggbug/12439.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 10:52 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12439.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跟我学XSL（一）——第一个XML文档</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/14/12438.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Thu, 14 Sep 2006 02:45:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/14/12438.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12438.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/14/12438.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12438.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12438.html</trackback:ping><description><![CDATA[
		<p>
		</p>
		<p>
		</p>
		<p>　　随着Internet的发展，越来越多的信息进入互联网，信息的交换、检索、保存及再利用等迫切的需求使HTML这种最常用的标记语言已越来越捉襟见肘。HTML将数据内容与表现融为一体，可修改性、数据可检索性差，而XML借鉴了HTML与数据库、程序语言的优点，将内容与表现分开，不仅使检索更为方便，更主要的是用户之间数据的交换更加方便，可重用性更强。</p>
		<p>　　XML是一种元标记语言，没有许多固定的标记，为WEB开发人员提供了更大的灵活性。当我们使用HTML时，标记只是简单的表示内容的显示形式，而与表示的内容没有任何关联，为文档的进一步处理带来极大的不便。比如要表示个人简历，用HTML的表示方式如下：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">HTML</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">BODY</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TABLE </span>
				<span style="COLOR: #ff0000">border</span>
				<span style="COLOR: #0000ff">=1 </span>
				<span style="COLOR: #ff0000">cellspacing</span>
				<span style="COLOR: #0000ff">=0</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TH</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">姓名</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TD</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">禹希初</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TH</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">性别</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TD</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">男</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TH</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">生日</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TD</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">1977.5<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TR</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TH</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">技能</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">TD </span>
				<span style="COLOR: #ff0000">colspan</span>
				<span style="COLOR: #0000ff">=5</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">数据库设计与维护、WEB开发<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">TABLE</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">BODY</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">HTML</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<br />
		<p align="center">
				<img height="49" alt="r_xsl_1.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/r_xsl_1.JPG" width="217" border="0" />
		</p>
		<p align="left">　在这里，我们无法从标记TH、TD得知其内容表示什么，如果用XML，相应的文档（文件名：个人简历.xml）就可写成如下形式：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;?</span>
				<span style="COLOR: #ff00ff">xml version="1.0" encoding="GB2312"</span>
				<span style="COLOR: #0000ff">?&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">resume</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">禹希初</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">sex</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">男</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">sex</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">birthday</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">1977.5</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">birthday</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">数据库设计与维护、WEB开发</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">skill</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">resume</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<p align="left">
				<img height="155" alt="o_xsl_2.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_2.JPG" width="335" border="0" />
				<br />
				<br />
		</p>
		<p>说明：</p>
		<p>　　version──规定了XML文档的版本，此处只能是1.0；</p>
		<p>　　encoding── 此处规定了XML文档的编码类型，此处取值为"GB2312"，也就是"简体中文"。</p>
		<p>　　对比两例，使用XML我们可以做到自定义标记，用标记表明内容的含义。这样在Internet上交流资料时，为用计算机处理文档提供了极大的方便，同时我们阅读源文件时也不会被一大堆格式弄得晕头转向。</p>
		<p>　　然而，由于XML并没有为标记规定显示方式，如果我们在游览器中查看以上两个文档（建议使用IE5.0或更新版本），我们将看到xml文档并没有以诸如表格的方式来显示。难道我们就不能像HTML一样显示文档吗？回答是否定的。以个人简历为例，需要另建一个格式文件说明各个标记的显示方式，其内容如下（假设文件名为resume.css）：</p>
		<p align="left">
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #800000">resume</span>
				<span id="Codehighlighter1_6_23_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #ff0000"> display</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff"> block</span>
						<span style="COLOR: #000000">;</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #800000">
						<br />name</span>
				<span id="Codehighlighter1_29_62_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #ff0000"> display</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff"> block</span>
						<span style="COLOR: #000000">;</span>
						<span style="COLOR: #ff0000"> font-size</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">120%</span>
						<span style="COLOR: #000000">;</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #800000">
						<br />sex</span>
				<span id="Codehighlighter1_67_99_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #ff0000"> display</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">block</span>
						<span style="COLOR: #000000">;</span>
						<span style="COLOR: #ff0000"> text-indent</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">2em</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #800000">
						<br />birthday</span>
				<span id="Codehighlighter1_109_141_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #ff0000"> display</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">block</span>
						<span style="COLOR: #000000">;</span>
						<span style="COLOR: #ff0000"> text-indent</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">2em</span>
						<span style="COLOR: #000000">}</span>
				</span>
				<span style="COLOR: #800000">
						<br />skill</span>
				<span id="Codehighlighter1_148_180_Open_Text">
						<span style="COLOR: #000000">{</span>
						<span style="COLOR: #ff0000"> display</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">block</span>
						<span style="COLOR: #000000">;</span>
						<span style="COLOR: #ff0000"> text-indent</span>
						<span style="COLOR: #000000">:</span>
						<span style="COLOR: #0000ff">2em</span>
						<span style="COLOR: #000000">}</span>
				</span>
		</div>
		<p>说明：</p>
		<p>　　以上均为CSS样式，建议读者参考有关资料熟悉CSS，在以后学习中必须用到，此处由于篇幅关系不作介绍。建立文件resume.css后，在个人简历.xml文件的第一行后添加以下文字：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;?</span>
				<span style="COLOR: #ff00ff">xml-stylesheet type="text/css" href="resume.css"</span>
				<span style="COLOR: #0000ff">?&gt;</span>
		</div>
		<img height="118" alt="o_xsl_3.JPG" src="http://www.cppblog.com/images/cppblog_com/ispfcn/1308/o_xsl_3.JPG" width="263" border="0" />
		<br />
		<p>说明：</p>
		<p>　　此处表示引用一个外部CSS样式文件，其中type规定样式类型（可取值为text/css或text/xsl），href规定文件路径。</p>
		<p>　　保存文件，再以IE5.0打开文件。怎么样？格式有些不一样吧。好象还不令人满意，文档内容是清晰了，但显示效果比HTML编写的文档就差得多了，XML编写的文档就只能以这种方式显示吗？！</p>
		<p>提示：</p>
		<p>　　1. 为了更好的理解与掌握XML，建议大家熟悉HTML 4.0与CSS 2.0语法；掌握JavaScript、VBscript中至少一种；编程经验、对数据库理论与SQL的了解均能使大家在学习XML时获益。</p>
		<p>　　2. XML文档中标记必须成对出现，如果是空标记也必须有前加"/"的同名标记结束，或使用此种文式&lt;xml_mark/&gt;表示空标记。</p>
		<p>　　3. XML以及下面将要介绍的XSL文档，属性值必须用双引号（"）或单引号（’）括起来。</p>
		<p>　　4. XML文档必须是良构的（XSL文档也是XML文档中一种），也就是说标记必须有结束标记、标记可以嵌套但不可交叉，如：<br /></p>
		<p>&lt;outer&gt;&lt;inner&gt;&lt;/inner&gt;&lt;inner/&gt;&lt;/outer&gt;</p>
		<p>是合法的，而下面的形式</p>
		<p>&lt;outer&gt;&lt;inner&gt;&lt;/outer&gt;&lt;/inner&gt;</p>
		<p>则是错误的。如果XML文档在浏览时出错，多半是违反了上面提到的规则。<br /></p>
<img src ="http://www.cppblog.com/ispfcn/aggbug/12438.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-14 10:45 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/14/12438.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>phpcms 3.0 url伪静态构造设置教程（apache和IIS）</title><link>http://www.cppblog.com/ispfcn/archive/2006/09/05/12047.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Tue, 05 Sep 2006 09:40:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/09/05/12047.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/12047.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/09/05/12047.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/12047.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/12047.html</trackback:ping><description><![CDATA[
		<span style="FONT-SIZE: 12px">phpcms 3.0提供按频道设置是否生成 html 的功能，当设置为不生成html时可以进行url静态化构造，以便于搜索收录。<br />例如：./article/list-1-5.html<br /><br />那么我们如何进行空间设置呢？下面将分别讲解apache和iis服务器环境下的配置方法：<br /><br />（1）Apache环境下的配置<br /><br />请首先咨询您的空间服务商，空间是否支持 Rewrite 以及是否支持对站点目录中 .htaccess 的文件解析，否则即便按照下面的方法设置好了，也无法使用。（需要服务器支持Apache的Mod_Rewrite功能）<br /><br /><br /><br /><br />将以下代码保存为.htaccess 并上传到网站目录下<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> 将 RewriteEngine 模式打开</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">RewriteEngine On<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> 修改以下语句中的 / 为你的网站目录地址，如果程序放在二级目录中，如/phpcms 请将 / 修改为 /phpcms</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">RewriteBase </span><span style="COLOR: #000000">/</span><span style="COLOR: #000000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> Rewrite 系统规则请勿修改</span><span style="COLOR: #008000"><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">RewriteRule </span><span style="COLOR: #000000">^</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">.*</span><span style="COLOR: #000000">)show</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">([</span><span style="COLOR: #800000">0</span><span style="COLOR: #000000">-</span><span style="COLOR: #800000">9</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">([</span><span style="COLOR: #800000">0</span><span style="COLOR: #000000">-</span><span style="COLOR: #800000">9</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">\.</span><span style="COLOR: #000000">html$ $</span><span style="COLOR: #800000">1</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">show</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">php</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">itemid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$</span><span style="COLOR: #800000">2</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">page</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$</span><span style="COLOR: #800000">3</span><span style="COLOR: #000000">  <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RewriteRule </span><span style="COLOR: #000000">^</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">.*</span><span style="COLOR: #000000">)list</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">([</span><span style="COLOR: #800000">0</span><span style="COLOR: #000000">-</span><span style="COLOR: #800000">9</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">([</span><span style="COLOR: #800000">0</span><span style="COLOR: #000000">-</span><span style="COLOR: #800000">9</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">\.</span><span style="COLOR: #000000">html$ $</span><span style="COLOR: #800000">1</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">list</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">php</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">catid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$</span><span style="COLOR: #800000">2</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">page</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$</span><span style="COLOR: #800000">3</span><span style="COLOR: #000000">  <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RewriteRule </span><span style="COLOR: #000000">^</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">.*</span><span style="COLOR: #000000">)show</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">([</span><span style="COLOR: #800000">0</span><span style="COLOR: #000000">-</span><span style="COLOR: #800000">9</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">\.</span><span style="COLOR: #000000">html$ $</span><span style="COLOR: #800000">1</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">show</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">php</span><span style="COLOR: #000000">?</span><span style="COLOR: #000000">specialid</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">$</span><span style="COLOR: #800000">2</span></div></span>
		<font size="2">或者直接用这个附件解压后传到网站目录下<br /><br />如果程序放在二级目录中，如/phpcms 按文件中注释修改<br /><br /><br />最后在频道设置中将<br />生成HTML方式设为:  不生成<br />URL静态化选项设为:   构造的URL类似于 ./list-1-5.html<br />生成文件的扩展名选项设为:   html<br /><br />文件下载地址：</font>
		<a href="http://bbs.phpcms.cn/attachment.php?aid=1192" target="_blank">
				<font color="#003366" size="2">http://bbs.phpcms.cn/attachment.php?aid=1192</font>
		</a>
		<br />
		<br />
		<br />
		<font size="2">（2）IIS服务器环境下的配置方法<br /><br />首先请下载以下附件: IIS Rewrite模块<br /><br />其中httpd.ini为配置文件内容如下:</font>
		<br />
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">[ISAPI_Rewrite]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000"> 3600 = 1 hour</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">CacheClockRate </span>
				<span style="COLOR: #800000">3600</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RepeatLimit </span>
				<span style="COLOR: #800000">32</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008000">#</span>
				<span style="COLOR: #008000"> Protect httpd.ini and httpd.parse.errors files<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /># from accessing through HTTP<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /># Rewrite 系统规则请勿修改 PHPCMS3.0</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">RewriteRule </span>
				<span style="COLOR: #000000">^</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">.*</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">show</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">([</span>
				<span style="COLOR: #800000">0</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #800000">9</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">([</span>
				<span style="COLOR: #800000">0</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #800000">9</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">\.</span>
				<span style="COLOR: #000000">html$ $</span>
				<span style="COLOR: #800000">1</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">show</span>
				<span style="COLOR: #000000">\.</span>
				<span style="COLOR: #000000">php</span>
				<span style="COLOR: #000000">\?</span>
				<span style="COLOR: #000000">itemid</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #800000">2</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">page</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #800000">3</span>
				<span style="COLOR: #000000">  <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RewriteRule </span>
				<span style="COLOR: #000000">^</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">.*</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">list</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">([</span>
				<span style="COLOR: #800000">0</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #800000">9</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">([</span>
				<span style="COLOR: #800000">0</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #800000">9</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">\.</span>
				<span style="COLOR: #000000">html$ $</span>
				<span style="COLOR: #800000">1</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">list</span>
				<span style="COLOR: #000000">\.</span>
				<span style="COLOR: #000000">php</span>
				<span style="COLOR: #000000">\?</span>
				<span style="COLOR: #000000">catid</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #800000">2</span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000">page</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #800000">3</span>
				<span style="COLOR: #000000">  <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RewriteRule </span>
				<span style="COLOR: #000000">^</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">.*</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">show</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">([</span>
				<span style="COLOR: #800000">0</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #800000">9</span>
				<span style="COLOR: #000000">]</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">)</span>
				<span style="COLOR: #000000">\.</span>
				<span style="COLOR: #000000">html$ $</span>
				<span style="COLOR: #800000">1</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">show</span>
				<span style="COLOR: #000000">\.</span>
				<span style="COLOR: #000000">php</span>
				<span style="COLOR: #000000">\?</span>
				<span style="COLOR: #000000">specialid</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">$</span>
				<span style="COLOR: #800000">2</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>将其解压到任意目录,如: C:\Rewrite<br /><br />打开“控制面板→管理工具→IIS信息服务管理器→网站→您的站点→属性”。在“ISAPI筛选器”项点击 “添加”， 筛选器名称填入Rewrite，可执行文件为C:\Rewrite\Rewrite.dll (如果您解压到其它目录请填入相应地址)<br /><br />重新启动IIS或重启计算机<br /><br /><br />最后在频道设置中将<br />生成HTML方式设为:  不生成<br />URL静态化选项设为:   构造的URL类似于 ./list-1-5.html<br />生成文件的扩展名选项设为:   html<br /><br />文件下载地址：<a href="http://bbs.phpcms.cn/attachment.php?aid=1262" target="_blank"><font color="#003366">http://bbs.phpcms.cn/attachment.php?aid=1262</font></a><br /><br />原文地址：<br /><br />http://bbs.phpcms.cn/thread-9693-1-1.html<br />http://bbs.phpcms.cn/thread-9952-1-1.html<br /><img src ="http://www.cppblog.com/ispfcn/aggbug/12047.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-09-05 17:40 <a href="http://www.cppblog.com/ispfcn/archive/2006/09/05/12047.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse+PHPEclipse+ Subversion+ TortoiseSVN </title><link>http://www.cppblog.com/ispfcn/archive/2006/04/04/4977.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Tue, 04 Apr 2006 03:05:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/04/04/4977.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/4977.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/04/04/4977.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/4977.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/4977.html</trackback:ping><description><![CDATA[
		<br />贴几个有用的链接：<br /><h3><a href="http://www-128.ibm.com/developerworks/opensource/library/os-debug/?ca=dgr-lnxw06PHPEclipse">Debugging techniques for PHP programmers</a></h3><h3><a href="http://www-128.ibm.com/developerworks/cn/opensource/os-subversion/">用 Subversion 构建版本控制环境</a></h3><a href="http://www.phpeclipse.de/tiki-view_articles.php">PHPEclipse官方站点</a><br /><br /><a href="http://www.subversion.org.cn/content/view/18/27/">Subversion快速入门教程</a><br /><br /><a href="http://subclipse.tigris.org/">Subclipse插件</a><br /><br /><a href="http://subversion.tigris.org/">Subversion官方网站</a><br /><br /><a href="http://tortoisesvn.tigris.org/">TortoiseSVN官方网站</a><br /><img src ="http://www.cppblog.com/ispfcn/aggbug/4977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-04-04 11:05 <a href="http://www.cppblog.com/ispfcn/archive/2006/04/04/4977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Zend Framework 手册中文版[连载]</title><link>http://www.cppblog.com/ispfcn/archive/2006/04/04/4976.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Tue, 04 Apr 2006 03:04:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/04/04/4976.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/4976.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/04/04/4976.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/4976.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/4976.html</trackback:ping><description><![CDATA[相信Zend Framework对于很多人都有借鉴意义（即使你不支持MVC），我打算花点业余时间把Zend Framework的手册翻译过来。应该对新手，老手都有点用 <!--emo&:)--><img style="VERTICAL-ALIGN: middle" alt="smile.gif" src="http://club.phpe.net/html/emoticons/smile.gif" border="0" /><!--endemo--><br /><br />翻译的路线是按我自己的的兴趣来安排的呵呵，ZF提供的那些类库，不一定会全部一一说明，因为我觉得大家可能都有自己的类库，不一定要用ZF的。主要还是看看它的框架。<br /><br />目前打算在这个版块和我的Blog上同步更新，等全部完成后，打包成chm文档提供下载。<br /><br />如果谁有兴趣参与，非常欢迎，请与我联系<br />msn &amp; email：haohappy at msn.com (at-&gt;@) <br /><span id="post51097">第一章. Zend<br /><br />目录<br /><br />1.1. 简介<br />1.2. Zend::loadFile()<br />1.3. Zend::loadClass()<br />1.4. Zend::loadInterface()<br />1.5. Zend::isReadable()<br />1.6. Zend::dump()<br />1.7. Zend::register()<br />1.8. Zend::registry()<br /><br />1.1.简介<br /><br />Zend类是Zend Framework的基类，之所以有这个类是为了使Zend Framework遵循DRY原则（Don't Repeat Yourself）。这个类只包含静态方法，这些类方法具有Zend Framework中的很多组件都需要的功能。<br /><span id="post51099">1.2. Zend::loadFile()<br /><br />Zend::loadFile()用来包含PHP文件。它其实是将PHP的include()函数封装而成的一个静态方法。当包含文件失败时，会抛出异常(Zend_Exception，见后面--Haohappy注)。<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">loadFile(</span><span style="COLOR: #800080">$filename</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$dirs</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$once</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">) <br /></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    <br /></span><span style="COLOR: #008080">3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />参数： 文件，目录(路径)，是否只包含一次 </span></div></span></span><!--Signature-->$filename参数指定需要加载的文件，注意$filename不需要指定任何路径，只需要文件名即可。ZF会对文件作安全性检查。$filename只能由字母，数字，连接符-,下划线_及英文句号.组成(半角)。$dir则不限，可以使用中文等。<br /><br />$dirs参数用来指定文件所在目录，如果为空，则程序将会到系统的include_path下寻找文件是否存在（include_path可在php.ini中设置--Haohappy注）<br /><br />$once参数为布尔类型，只能是true或false，两者区别就和include()和include_once()的区别一样。 <br /><span id="post51100">1.3. Zend::loadClass()<br /><br />Zend::loadClass()用来加载一个PHP类文件，这个文件的文件名必须和文件中的类同名。loadClass()会检查文件中的类是否存在。如果文件中的类不存在，那么就会抛出一个Zend_Exception异常。<br /><br /><span style="COLOR: green">(例：TestClass.php中有个类TestClass，使用Zend::loadClass("TestClass")就可加载这个类，这种作法类似于Java-- Haohappy注)</span><br /><!--c1--><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">loadClass(</span><span style="COLOR: #800080">$class</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$dirs</span><span style="COLOR: #000000">) <br /></span><span style="COLOR: #008080">2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />参数： 类，目录</span></div></span>如果没有指定$dirs参数，而文件名中存在下划线，那么loadClass()会自动把下划线当成目录分隔符，去相应的目录中去查找文件。<br /><br />例如：loadClass("Zend_Example_Class") 没指定$dirs参数 ，则 loadClass()会自动到Zend/Example/目录下去查找Class.php文件 <br /><span id="post51101">1.4. Zend::loadInterface()<br /><br />Zend::loadInterface()和Zend::loadClass()的用法是一样的，区别在于loadInterface()是用来加载接口。Zend::loadClass() 不能用来加载接口，因为PHP函数class_exists()不能检查Interface是否存在（PHP 5.0.2之前版本），所以需要用Zend::loadInterface()来代替。<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">loadInterface(</span><span style="COLOR: #800080">$interface</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$dirs</span><span style="COLOR: #000000">)</span></div></span>同样，如果你没有指定目录，但是文件中含有下划线_，Zend::loadInterface()也会自动到相应目录去寻找文件，这和Zend::loadClass()是一样的。 <br /><span id="post51102"><br />1.5. Zend::isReadable()<br /><br />判定某个文件是否可读，可读则返回true，否则返回false。<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">isReadable(</span><span style="COLOR: #800080">$filename</span><span style="COLOR: #000000">)</span></div></span>这个方法是将PHP函数is_readable()封装而成的， is_readable()不会自动查找include_path下的文件，而Zend::isReadable()可以。 <!--Signature--><br /><br /><span id="post51103">1.6. Zend::dump()<br /><br />Zend::dump()打印和返回某个表达式或变量的信息。它是将var_dump()封装而成的。它默认带上了<br />(X)HTML的&lt;pre&gt;标签，使输出更美观。<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">dump(</span><span style="COLOR: #800080">$var</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$label</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$echo</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">)</span></div></span>$label标签参数是用来加在输出信息之前的一段文本。<br /><br /><span style="COLOR: green">(这非常有用，例如你一次要查看多个变量的信息，你可以为不同变量设置不同label，如“user”，“password”等等，这样不会弄乱--Haohappy注)</span><br /><br />dump()总会返回信息，但不一定会输出，这取决于$echo参数，指定是否要将信息输出到屏幕。 <!--Signature--><br /><br /><span id="post51146">1.7. Zend::register()<br /><br />注册一个对象<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">register(</span><span style="COLOR: #800080">$name</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$object</span><span style="COLOR: #000000">)</span></div></span>ZendFramework的"注册表"是一个提供单件对象(singleton instances)给应用程序的机制. 通过注册一个对象,你可以在你需要时再取得这个对象.<br /><br />$name是对象名称,指定后你可以通过$name来访问这个对象.<br /><br />$name参数必须是一个字符串。在注册库中只能存储对象，对象将不会被删除，而一个对象只能有一个实例。　如果不符合这几个条件，就会抛出一个Zend_Exception异常。 <!--Signature--><br /><br /><span id="post51147">1.8. Zend::registry()<br /><br />在“对象注册表”中返回一个对象，或者列出所有已经注册的对象<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080">1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">registry(</span><span style="COLOR: #800080">$name</span><span style="COLOR: #000000">=</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)</span></div></span>如果$name参数为空，会返回一个数组，key为对象名称，value为对象的类名称。<br /><br />如果$name参数为字符串，将返回相应的对象。如果对象不存在，抛出Zend_Exception异常。 <img src ="http://www.cppblog.com/ispfcn/aggbug/4976.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-04-04 11:04 <a href="http://www.cppblog.com/ispfcn/archive/2006/04/04/4976.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP5中的SOAP扩展的应用及注意的问题</title><link>http://www.cppblog.com/ispfcn/archive/2006/04/04/4975.html</link><dc:creator>编程之道</dc:creator><author>编程之道</author><pubDate>Tue, 04 Apr 2006 03:03:00 GMT</pubDate><guid>http://www.cppblog.com/ispfcn/archive/2006/04/04/4975.html</guid><wfw:comment>http://www.cppblog.com/ispfcn/comments/4975.html</wfw:comment><comments>http://www.cppblog.com/ispfcn/archive/2006/04/04/4975.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ispfcn/comments/commentRss/4975.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ispfcn/services/trackbacks/4975.html</trackback:ping><description><![CDATA[
		<p>既然说到SOAP就先对这个有个大概了解吧。</p>
		<p>SOAP（简单对象访问协议）定义了客户机与服务器之间传递的消息。消息采用 XML 格式。SOAP 独立于平台、编程语言、网络和传输层。</p>
		<p>这次做的项目中需要提供WebService服务，没话说，由于是PHP的项目，首先就按照习惯用了NuSOAP，结果让我郁闷了好久，程序返回的是一个数组，但是用print_r()打印出来是空的，用count()看了一下大小为1，郁闷ing。看了一下response数据是存在的啊。又对照了一下以前做的SOAP（是在PHP4上的），两个response有点不同，这才反应过来是PHP5跟PHP4的版本不一样。</p>
		<p>打开php.ini，找到扩展模块那部分，把soap的模块加载上，又重新写了一下Server端和Client端，继续测试。总是出现“looks like we got no XML document”的error。难道是用法错了，手头正好有本《PHP5 Power Programming》找到SOAP的地方，没找到问题，又跑到zend的官方网站上看了一下SOAP的介绍和示例（<a href="http://www.zend.com/php5/articles/php5-SOAP.php?out=dynamicwebpages"><font color="#666666">http://www.zend.com/php5/articles/php5-SOAP.php?out=dynamicwebpages</font></a>），没错啊。去Google搜索这个错误，最后还是连到了zend的一个blog上（<a href="http://www.zend.com/php5/articles/php5-SOAP.php?article=php5-SOAP&amp;kind=php5&amp;id=5085&amp;open=1&amp;anc=0&amp;view=1"><font color="#666666">http://www.zend.com/php5/articles/php5-SOAP.php?article=php5-SOAP&amp;kind=php5&amp;id=5085&amp;open=1&amp;anc=0&amp;view=1</font></a>），前半部分跟上面那个是一样的，直接跳过，看下面的Comment，发现好多人都遇到了这个问题，人提到是在PHP开始标签之前存在blank character，可我的没有啊，我的有个require_once("mainfile.php")，把这句注释掉以后就没问题了，又继续根据mainfile.php追踪下去，发现是在类的文件中PHP结束标签之后有blank character，删除掉就没问题了。</p>
		<p>在zend上的comments里还有人提到是XML文件的编码问题，这个我没有测试。终于搞定了这个问题，继续写接口，哎……</p>
		<p>郁闷本来想把全部代码贴上来，结果排版会有问题，还是贴些重要的吧！</p>
		<p>Server端：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080">1</span>
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #800080">$web_service</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> SoapServer(</span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">array</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">uri</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=&gt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">ispfcn</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">encoding</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">=&gt;</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">gb2312</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">)); <br /></span>
				<span style="COLOR: #008080">2</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #800080">$web_service</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">addFunction(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">iGetUserList</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #008080">3</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #800080">$web_service</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">addFunction(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">iRegisterUser</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #008080">4</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #800080">$web_service</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">addFunction(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">iSetUserPwd</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #008080">5</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #800080">$web_service</span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000">handle();</span>
		</div>
		<br />Client端：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080"> 1</span><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$opts</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">array</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">location</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=&gt;</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">http://192.168.0.56/web_service.php</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">uri</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">=&gt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">ispfcn</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">encoding</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">=&gt;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">gb2312</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$client</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SoapClient(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$opts</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$custom_id</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$custom_name</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">system</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$custom_pwd</span><span style="COLOR: #000000">=</span><span style="COLOR: #008080">md5</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">system</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$custom_flag</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">sys</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$start</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$limit</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$client</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">iGetUserList(</span><span style="COLOR: #800080">$custom_id</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$custom_name</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$custom_pwd</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$custom_flag</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$start</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$limit</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #008080">count</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000">);</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">sprintf</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%4d</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">user_id</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">])</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$result</span><span style="COLOR: #000000">[</span><span style="COLOR: #800080">$i</span><span style="COLOR: #000000">][</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">username</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />    }<br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}<br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (SoapFault </span><span style="COLOR: #800080">$e</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />{<br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$e</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">faultcode</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$e</span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000">faultstring</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />}</span></div><img src ="http://www.cppblog.com/ispfcn/aggbug/4975.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ispfcn/" target="_blank">编程之道</a> 2006-04-04 11:03 <a href="http://www.cppblog.com/ispfcn/archive/2006/04/04/4975.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>