使用Xslt对Xml进行排序,并通过下拉列表更改排序列

问题描述:

我已经将xml加载到我的项目中,并使用xmltransform类来应用Xslt,以便它可以按特定列对文档进行排序(同时也使用Xpath).我需要能够通过更改Dropdownlist将页面上的排序更改为不同的列.

我尝试了各种不同的方法,但是都没有成功---有人有任何想法吗?

I have loaded a xml into my project and used xmltransform class to apply the Xslt so that it would sort the document by a particular column (while also using Xpath). I need to be able to change the sorting on the page to different columns by changing a Dropdownlist.

I have tried various different ways, but with no success --- Does anyone have any Ideas?

为此,您需要使用参数和将Dropdownlist值传递给XSL.根据您在XSL中收到的参数值,应用xsl:sort语句.大约需要执行以下操作

C#代码
For this you need to pass Dropdownlist value to XSL using parameter and based on param value which you have received in XSL apply xsl:sort statement. Roughly you need to do following

C# CODE
XslCompiledTransform tras = new XslCompiledTransform();
XsltArgumentList argList = new XsltArgumentList();
argList.AddParam("sortfield", "", "dd value");
tras.Transform("XMLfile", argList, sw);



XSL标头



XSL Header

<xsl:output method="html" indent="yes"/>
<xsl:param name="sortfield"></xsl:param>