对数据岛数据实现动态排序二法[1]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 colee 的 blog


现在数据岛被越来越广泛的应用;其中必然会涉及到的就是动态排序了;下面列出两种实现方法:

1、为<xsl:param>标签设定参数实现动态排序(推荐)
<html>
<body>
<table datasrc="#catalogs" border=1>
<thead>
<tr>
<td onclick="sort('title','descending');">title</td>
<td>artist</td>
<td onclick="sort('country','ascending');">country</td>
<td>company</td>
<td>price</td>
<td>year</td>
</tr>
</thead>
<tbody>
<tr>
<td ><div datafld="title"></div></td>
<td ><div datafld="artist"></div></td>
<td ><div datafld="country"></div></td>
<td ><div datafld="company"></div></td>
<td ><div datafld="price"></div></td>
<td ><div datafld="year"></div></td>
</tr>
</tbody>
</table>

<xml id="catalogs">
<catalog>
<cd>
<title>empire burlesque</title>
bob dylan
<country>usa</country>
<company>columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>burlesque</title>
dylan
<country>ua</country>
<company>umbia</company>
<price>1.90</price>
<year>1987</year>
</cd>
<cd>
<title>empire</title>
bob
<country>us</country>
<company>bia</company>
<price>12.90</price>
<year>1995</year>
</cd>
</catalog>
</xml>

<xml id="xstyle">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0">
<xsl:output method="xml"/>
<xsl:param name="sortorder" select="'descending'"/>
<xsl:param name="sortfield" select="'xxx'"/>
<xsl:template match="/">
<catalog>
<xsl:for-each select="catalog/cd">
<xsl:sort select="*[name()=$sortfield]" order="{$sortorder}" />
<cd>
<title><xsl:value-of select="title"/></title>
<xsl:value-of select="artist"/>
<country><xsl:value-of select="country"/></country>
<company><xsl:value-of select="company"/></company>
<price><xsl:value-of select="price"/></price>
<year><xsl:value-of select="year"/></year>
</cd>
</xsl:for-each>
</catalog>
</xsl:template>
</xsl:stylesheet>
</xml>

<script language="vbscript">
function sort(strsortfield, strsortorder)

  dim objxsl, objxml, objtemplate, objprocessor, strhtml, strdrinktype
 
  set objxml = createobject("msxml2.freethreadeddomdocument")
  set objxsl = createobject("msxml2.freethreadeddomdocument")
  
  'load the xml document
  objxml.async = false
  objxml.loadxml catalogs.xml  
  
  'load the xsl document
  objxsl.async = false
  objxsl.loadxml xstyle.xml
     
  'create an instance of our xsl template object
  set objtemplate = createobject("msxml2.xsltemplate")
     
  'create an instance of our stylesheet object using our recently loaded xslt document
  set objtemplate.stylesheet = objxsl
      
  'create an instance of our processor object
  set objprocessor = objtemplate.createprocessor

  'define the input object for our object equal to our recently loaded xml document
  objprocessor.input = objxml

  'now, finally we can add any parameters that we require to our template processor
  objprocessor.addparameter "sortfield", strsortfield
  objprocessor.addparameter "sortorder", strsortorder
     
  'last but not least we do our transformation
  objprocessor.transform
     
  'store the results of the output into a string.
  strxml = objprocessor.output

  'load up an xml dom object from the recent xml output
  objxml.loadxml strxml
  
  'select only the "employees" elements from our document object
  objxml.selectnodes("//catalog")
  
  'load our data island using our new xml object
  catalogs.loadxml  objxml.xml  

本文关键:xmlDSO,xmldom,xsl,动态排序
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top