Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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/8/xslt/3.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
Xml XSLT 1.0版,“选择”然后“存储”到数组中,然后“排序”数组和显示数组_Xml_Xslt_Xslt 1.0_Xslt Grouping - Fatal编程技术网

Xml XSLT 1.0版,“选择”然后“存储”到数组中,然后“排序”数组和显示数组

Xml XSLT 1.0版,“选择”然后“存储”到数组中,然后“排序”数组和显示数组,xml,xslt,xslt-1.0,xslt-grouping,Xml,Xslt,Xslt 1.0,Xslt Grouping,我是XSLT世界的新手。我只是想知道如何将我的select结果保存到一个数组中并对该数组进行排序,然后选择我想要的数组索引并显示。在谷歌搜索了一下这个问题后,我能够在字段上使用sort。但我不想在XML内部玩,因为它将非常长和复杂,而我更喜欢存储结果,然后再到处玩 <?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <title>Empire Burlesque<

我是XSLT世界的新手。我只是想知道如何将我的select结果保存到一个数组中并对该数组进行排序,然后选择我想要的数组索引并显示。在谷歌搜索了一下这个问题后,我能够在字段上使用sort。但我不想在XML内部玩,因为它将非常长和复杂,而我更喜欢存储结果,然后再到处玩

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
    <cd>
        <title>Empire Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
                <date>2023-01-01</date>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
                <date>2022-01-01</date>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
                <date>2021-01-01</date>
    </cd>
</catalog>
XSLT:


那么,我如何在一个地方收集所有日期,然后对它们进行排序呢。谢谢

你的问题不清楚。XML/XSLT中没有这样的数组。如果愿意,可以定义一个变量来存储所有日期。尽管所有这些存储都是对原始节点的引用。您还可以定义一个变量来包含原始节点的副本,例如排序后。我尝试过,但这只给我一个日期2023-01-01,而不是所有日期。否,它包含所有日期,前提是您从/的上下文中执行此操作。但是,如果您使用xsl:value of测试内容,那么在XSLT1.0中只会得到第一个。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
        <th>Date</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <xsl:sort select="date"/>
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
        <td><xsl:value-of select="date"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>