Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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中的排序?_Xml_Xslt - Fatal编程技术网

Xml XSLT中的排序?

Xml XSLT中的排序?,xml,xslt,Xml,Xslt,我是XSLT新手,我想将XML数据转换成HTML表,然后根据preis字段对表进行排序:这是我的代码,但它不起作用。请告诉我代码中的问题是什么: <xsl:stylesheet> <xsl:template match="/"> <html> <body> <h1> Hallo </h1> <table border="1">

我是XSLT新手,我想将XML数据转换成HTML表,然后根据preis字段对表进行排序:这是我的代码,但它不起作用。请告诉我代码中的问题是什么:

<xsl:stylesheet>
<xsl:template match="/">
    <html>
      <body>
        <h1>
          Hallo
        </h1>
        <table border="1">

          <xsl:apply-templates>
            <xsl:sort select="preis" data-type="number" order="ascending"/>
          </xsl:apply-templates>

        </table>  
      </body>
    </html>
  </xsl:template>
  <xsl:template match="artikel">
    <tr>

      <xsl:apply-templates select="name" />
      <xsl:apply-templates select="lieferant" />
      <xsl:apply-templates select="preis"/>
    </tr> 
  </xsl:template>
  <xsl:template match="name|lieferant|preis">
    <td>
      <xsl:value-of select="."/>
    </td> 
  </xsl:template>

</xsl:stylesheet>

你好
和XML文件:

<lieferungen>
  <artikel id="3526">
    <name>apfel</name>
    <lieferant>Fa. Krause</lieferant>
    <preis stueckpreis="true">8.97</preis>
  </artikel>
  <artikel id="7866">
    <name>Kirschen</name>
    <preis stueckpreis="false">10.45</preis>
    <lieferant>Fa. Helbig</lieferant>
  </artikel>
  <artikel id="3526">
    <preis stueckpreis="true">12.67</preis>
    <lieferant>Fa. Liebig</lieferant>
    <name>apfel</name>
  </artikel>
  <artikel id="7866">
    <preis stueckpreis="false">17.67</preis>
    <name>Kirschen</name>
    <lieferant>Fa. Krause</lieferant>
  </artikel>
  <artikel id="3627">
    <name>apfel</name>
    <lieferant>Fa. Mertes</lieferant>
    <preis stueckpreis="true">9.54</preis>
  </artikel>
  <artikel id="7866">
    <name>Kirschen</name>
    <lieferant>Fa. Hoeller</lieferant>
    <preis stueckpreis="false">16.45</preis>
  </artikel>
  <artikel id="7868">
    <preis>3.20</preis>
    <name>Kohl</name>
    <lieferant>Fa. Hoeller</lieferant>
  </artikel>
  <artikel id="7866">
    <name>Kirschen</name>
    <lieferant>Fa. Richard</lieferant>
    <preis stueckpreis="false">12.45</preis>
  </artikel>
  <artikel id="3245">
    <preis stueckpreis="false">15.67</preis>
    <name>Bananen</name>
    <lieferant>Fa. Hoeller</lieferant>
  </artikel>
  <artikel id="6745">
    <name>Kohl</name>
    <lieferant>Fa. Reinhardt</lieferant>
    <preis stueckpreis="false">3.10</preis>
  </artikel>
  <artikel id="7789">
    <name>Ananas</name>
    <preis stueckpreis="true">8.60</preis>
    <lieferant>Fa. Richard</lieferant>
  </artikel>
</lieferungen>

阿普费尔
Fa。克劳斯
8.97
基尔申
10.45
Fa。赫尔比希
12.67
Fa。利比希
阿普费尔
17.67
基尔申
Fa。克劳斯
阿普费尔
Fa。梅特斯
9.54
基尔申
Fa。霍勒
16.45
3.20
科尔
Fa。霍勒
基尔申
Fa。理查德
12.45
15.67
巴纳宁
Fa。霍勒
科尔
Fa。莱因哈特
3.10
阿纳纳斯
8.60
Fa。理查德

如果我理解你的问题,这应该行得通

顺便说一句!对于所有项目,项目标记内的子标记顺序不同

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
<xsl:template match="/">
<xsl:for-each select="lieferungen/artikel">
<xsl:sort select="preis" data-type="number" order="ascending"/>
    <td>
      <xsl:copy-of select="."/>
    </td>
</xsl:for-each>
</xsl:template>

</xsl:transform>

产出:

<td xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <artikel id="6745">
    <name>Kohl</name>
    <lieferant>Fa. Reinhardt</lieferant>
    <preis stueckpreis="false">3.10</preis>
</artikel>
</td>
<td xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <artikel id="7868">
    <preis>3.20</preis>
    <name>Kohl</name>
    <lieferant>Fa. Hoeller</lieferant>
  </artikel>
</td>
<td xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <artikel id="7789">
    <name>Ananas</name>
    <preis stueckpreis="true">8.60</preis>
    <lieferant>Fa. Richard</lieferant>
  </artikel>
</td>
...
...
<td xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <artikel id="7866">
    <preis stueckpreis="false">17.67</preis>
    <name>Kirschen</name>
    <lieferant>Fa. Krause</lieferant>
  </artikel>
</td>

科尔
Fa。莱因哈特
3.10
3.20
科尔
Fa。霍勒
阿纳纳斯
8.60
Fa。理查德
...
...
17.67
基尔申
Fa。克劳斯

如果没有输入XML、所需输出和实际输出的示例,我们怎么知道“不起作用”是什么意思呢?我的意思是价格(数字)应该是排序访问下降还是下降现在你让事情变得更加混乱了。你需要上升还是下降?同样,如果不理解“不起作用”的确切含义,我们也无能为力。这两个词都不起作用。我将最后一次请您解释“不起作用”的确切含义——提供XML示例、预期输出和当前输出。如果我在接下来的一个小时内没有看到这些,我将投票结束这个问题。