Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用XSLT对asp:listview数据源xml进行自定义分组和排序_Asp.net_Xml_Xslt - Fatal编程技术网

Asp.net 使用XSLT对asp:listview数据源xml进行自定义分组和排序

Asp.net 使用XSLT对asp:listview数据源xml进行自定义分组和排序,asp.net,xml,xslt,Asp.net,Xml,Xslt,我有一个listview,它获取一个xmldatasource作为其数据源。xmldatasource是动态创建和分配的。在将数据绑定到listview之前使用xpath listview.datasource = myxmlsource listview.DataBind() 使用xpath=“root/node”只选择node元素。因此,我认为应用xpath后的xml结构如下所示: <node name="Albert" age="32" desc="some random des

我有一个listview,它获取一个xmldatasource作为其数据源。xmldatasource是动态创建和分配的。在将数据绑定到listview之前使用xpath

 listview.datasource = myxmlsource
listview.DataBind()
使用
xpath=“root/node”
只选择node元素。因此,我认为应用xpath后的xml结构如下所示:

<node name="Albert" age="32" desc="some random description" region="north"/>
<node name="Randy" age="32" desc="some random description" region="south"/>
<node name="Zebra" age="32" desc="some random description"region="east"/>
<node name="Bob" age="32" desc="some random description"region="south"/>
<node name="Carl" age="32" desc="some random description"region="north"/>
<node name="Denver" age="32" desc="some random description"region="east"/>

请注意,它没有根。我正在尝试对这个XSLT进行排序

这里的目的是按区域对xml进行分组,然后按区域对xml进行排序 名字

我对XSLT还不熟悉,它似乎是一个怪兽

到目前为止,我能想到的xslt代码是:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl my" xmlns:my="http://tempuri.org"
>
  <xsl:output method="xml" indent="yes"/>

    <xsl:template name="@*|node()">

      <xsl:copy>
        <xsl:apply-templates select="@*|node() >
          <xsl:sort select="@region" order="ascending"/>
          <xsl:sort select="@name"/>
        </xsl:apply-templates>
      </xsl:copy>    
    </xsl:template>    

</xsl:stylesheet>


您的XSLT几乎正确-模板应该具有
match=“…”
属性,而不是
name=“…”
属性-以下是工作版本:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl my" xmlns:my="http://tempuri.org"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()">
        <xsl:sort select="@region" order="ascending"/>
        <xsl:sort select="@name"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

<?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
      <xsl:output method="xml" indent="yes"/>

        <xsl:template match="@*|node()">
          <xsl:copy>
            <xsl:apply-templates select="node[@region='north']" >
              <xsl:sort select="@name"/>
            </xsl:apply-templates>
          </xsl:copy>    
           <xsl:copy>
            <xsl:apply-templates select="node[@region='east']" >
              <xsl:sort select="@name"/>
            </xsl:apply-templates>
          </xsl:copy>    
          <xsl:copy>
            <xsl:apply-templates select="node[@region='south']" >
              <xsl:sort select="@name"/>
            </xsl:apply-templates>
          </xsl:copy>  
        </xsl:template>    

    </xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl my" xmlns:my="http://tempuri.org"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()">
        <xsl:sort select="@region" order="ascending"/>
        <xsl:sort select="@name"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>