This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
How to get unique data
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] How to get unique data
- From: Rick Zhang <rickzhang at sina dot com>
- Date: Thu, 08 Nov 2001 06:56:45 +0800
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi,
In SQL "Select Distinct ...." can get the unique data form the specify table. But in xml I can not do the same work.
The data is as following:
<prog pid="0">
<item iid="0" fid="1"/>
<item iid="0" fid="2"/>
<item iid="0" fid="3"/>
<item iid="0" fid="4"/>
<item iid="0" fid="5"/>
<item iid="1" fid="6"/>
<item iid="1" fid="7"/>
<item iid="1" fid="8"/>
<item iid="1" fid="9"/>
<item iid="1" fid="10"/>
</prog>
<prog pid="1">
<item iid="2" fid="11"/>
<item iid="2" fid="12"/>
<item iid="2" fid="13"/>
<item iid="2" fid="14"/>
<item iid="2" fid="15"/>
<item iid="3" fid="16"/>
<item iid="3" fid="17"/>
<item iid="3" fid="18"/>
<item iid="3" fid="19"/>
<item iid="3" fid="20"/>
</prog>
How can I use xsl in IE to get the follow data:
<prog pid="0">
<item iid="0" fid="1"/>
<item iid="1" fid="6"/>
</prog>
<prog pid="1">
<item iid="2" fid="11"/>
<item iid="3" fid="16"/>
</prog>
fid attribute's value here is not important, I just want to the first item element with the unique iid.
I use the follow xsl
...
<xsl:for-each select="//prog" order-by="@pid">
<xsl:for-each select="item" order-by="@iid">
<xsl:if exp="!checkDup( @iid )">
...show the unique data...
</xsl:if>
</xsl:for-each>
</xsl:for-each>
...
<xsl:script language="javascript">
<![CDATA[
var arrItemName = new Array();
function checkDup( item )
{
var isDup = false;
for ( i = 0; i<arrItemName.length; i++ )
{
if ( arrItemName[i] == item ){
isDup = true;
break;
}
}
if ( isDup==false ){
var len = arrItemName.length;
arrItemName.length ++;
arrItemName[len] = item;
}
return isDup;
}
]]>
</xsl:script>
IE reported no error but still give the duplicate data, why??? Can anyone help me out???
______________________________________
我的QQ : 329170
我的ICQ : 37175293
我的论坛: http://www3.ccw.com.cn c/c++
===================================================================
新浪免费电子邮箱 (http://mail.sina.com.cn)
新浪分类信息--城市生活指南! (http://classad.sina.com.cn/)
七种手机图片、千首铃声下载……新浪短信无限精彩! (http://sms.sina.com.cn/)
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list