📄 creating a comma-separated list of items.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0068)file://G:\application\XSL%20uguid\Authoring%20Well-Formed%20HTML.htm -->
<HTML><HEAD><TITLE>使用context方法生成一个逗号分割的项目链表 </TITLE>
<META content="text/html; charset=gb_2312-80" http-equiv=Content-Type>
<STYLE type=text/css>.normal10 {
FONT-SIZE: 11pt
}
.normal9 {
FONT-SIZE: 9pt
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: red; TEXT-DECORATION: underline
}
A {
COLOR: cornflowerblue; FONT-FAMILY: "新细明体", "宋体"; FONT-SIZE: 11pt; FONT-WEIGHT: bold
}
.normal105 {
FONT-SIZE: 11pt
}
.p {
FONT-SIZE: 11pt
}
</STYLE>
<LINK href="level_2_2.files/Global.css" tppabs="http://www.xml.org.cn:8188/application/XSL%20uguid/level_2_2.files/Global.css" rel=stylesheet>
<META content="MSHTML 5.00.2014.210" name=GENERATOR></HEAD>
<BODY>
<P align=center class=normal105>[<A href="file:///G:/default.asp"
target=_parent>返回首页</A>][<FONT face=宋体 lang=ZH-CN><A
href="file:///G:/application/application.htm"
target=_parent>返回实践应用</A></FONT>]</P>
<TABLE align=center border=0 width="85%">
<TBODY>
<TR>
<TD height=63 width="14%"> </TD>
<TD height=63 width="71%">
<H2 align=center><font size="4">使用context方法生成一个逗号分割的项目链表</font></H2>
</TD>
<TD height=63 width="15%"><a name=top></a></TD>
</TR>
<TR>
<TD colSpan=3 height=43>
<P><SPAN class=normal105><SPAN class=normal105>上一篇:<a href="Placing a List of Items into a Grid with the context() Method.htm" tppabs="http://www.xml.org.cn:8188/application/XSL%20uguid/Placing%20a%20List%20of%20Items%20into%20a%20Grid%20with%20the%20context%28%29%20Method.htm">使用context()方法在一个grid表格中安排一个项目链表</a>
<BR>
返 回 :<a href="XSL Patterns.htm" tppabs="http://www.xml.org.cn:8188/application/XSL%20uguid/XSL%20Patterns.htm">XSL模式语言 </a></SPAN></SPAN></P>
<P><b><span class="normal105">context()</span></b><span class="normal105">
方法提供了一种机制来测试一个节点在一个查询的上下文中位置.作为演示,我们可以提取一系列元素并且把他们显示成为一个有逗号分割的链表.在这个杨立中,你需要在每一个产品之间插入了一个逗号,除了最后一个.</span></P>
<p> <b><span class="normal105">end()</span></b><span class="normal105">方法能被用于决定是否这个元素是这个查询中的最后一个元素<b>.</b>当你真正希望".[not(end())]"能被应用于在<xsl:for-each>之前的找到的"products/product"查询的时候,由于<b>end()</b>是应用于"."查询,所以".[not(end())]"
将不会产生期望的结果.<b>context()</b>指出了正确的节点,和作为结果的模板成为了如下的形式:</span></p>
<pre class=clsCode><font face="Arial, Helvetica, sans-serif" size="2" class="normal105"><DIV>
<xsl:for-each select="products/product">
<xsl:value-of /><xsl:if test="context()[not(end())]">, </xsl:if>
</xsl:for-each>
</DIV></font></pre>
<p class="normal105">由于逗号的插入是基于查询的位置而不是基于基于源文档的位置,这个链表可以被查询但不会打乱结果.下面的样板显示了如何再一个被排序的产品链表中加入一个逗号.</p>
<pre class=clsCode><font face="Arial, Helvetica, sans-serif" size="2" class="normal105"><DIV>
<xsl:for-each select="products/product" order-by="-.">
<xsl:value-of /><xsl:if test="context()[not(end())]">, </xsl:if>
</xsl:for-each>
</DIV></font></pre>
<p><b><span class="normal105">order-by</span></b><span class="normal105">
属性被赋值为"-."来指出是按照产品名称的降序排列.</span></p>
<p><b><span class="normal105">尝试!</span></b><span class="normal105"> 在<a
href="../../../msdn.microsoft.com/xml/samples/product-list/product-list2.xml" tppabs="http://msdn.microsoft.com/xml/samples/product-list/product-list2.xml">Product
List (Commas) Sample</a>.中浏览上面的样板.</span></p>
<p><a
href="../../../msdn.microsoft.com/xml/samples/product-list/product-list2.zip" tppabs="http://msdn.microsoft.com/xml/samples/product-list/product-list2.zip"><span class="normal9"><span class="normal105"><img
alt=Download border=0 height=20
src="Creating a Comma-Separated List of Items with the context() Method.files/icodownl.gif" tppabs="http://www.xml.org.cn:8188/application/XSL%20uguid/Creating%20a%20Comma-Separated%20List%20of%20Items%20with%20the%20context%28%29%20Method.files/icodownl.gif"
width=16> <span class="normal105">Download this sample</span></span></span></a><span class="normal105"><span class="normal9">.
</span></span></p>
</TD></TR>
<TR>
<TD colSpan=3 height=57><FONT face=宋体 lang=ZH-CN
size=3></FONT><REV></REV><FONT face=宋体 lang=ZH-CN size=3></FONT>
<HR SIZE=1>
<P align=center><FONT face=宋体 lang=ZH-CN>[<A
href="file:///G:/application/XSL%20uguid/Authoring%20Well-Formed%20HTML.htm#top">返回标题</A>][<A
href="file:///G:/application/application.htm" target=_parent>返回实践应用</A>][<A
href="file:///G:/default.asp" target=_parent>返回首页</A>][<A
href="mailto:xmlteam@egroups.com">欢迎投稿</A>]</FONT></P>
<P align=center>最后更新:1999年10月28日<BR>
<FONT color=#ff0033
size=-1>本站点所刊文章版权,均归本站点所有。署名作者拥有其著作权。<BR>
未经</FONT><FONT color=#ff0033><A
href="mailto:xmlteam@egroups.com"><FONT color=#6666ff
size=-1>允许</FONT></A></FONT><FONT color=#ff0033
size=-1>,不得随意转载,违者必究!!</FONT> </P>
</TD></TR></TBODY></TABLE>
<H2 align=center> </H2><FONT face=宋体 lang=ZH-CN size=3>
<P align=justify> </P></FONT><FONT face=宋体 lang=ZH-CN
size=3></FONT></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -