/ / Triedenie xslt nefunguje v xslt - xml, xslt

Triedenie xslt nefunguje v xslt - xml, xslt

Napísal som blok XSLT a chcem triediť svoj xml súbor, ale to nefunguje.

môj XSLT:

  .....
<xsl:template match="/">
<html>
<body>
<h1>The second one that i can sort the result</h1>
<table>
<tr bgcolor="blue">
<th>Name</th>
<th>ID</th>
<th>preis</th>
<th>Lieferant</th>
</tr>
<xsl:for-each select="//lieferungen/artikel">
<tr>
<xsl:apply-templates select="name"/>
<td><xsl:value-of select="@id"/></td>
<td><xsl:apply-templates><xsl:sort select="preis" order="ascending"/</xsl:apply-templates></td>
<xsl:apply-templates select="lieferant"/>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="name">
<td><xsl:value-of select="node()"/></td>
</xsl:template>
<xsl:template match="lieferant">
<td><xsl:value-of select="node()"/></td>
</xsl:template>
</xsl:stylesheet>

a xml je:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="C:UsersBabakDesktopXSLTsort.xslt"?>
<!-- Edited by XMLSpy® -->
<lieferungen
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:myspace:lieferungen ....">
<artikel id="3526">
<name>apfel</name>
<preis stueckpreis="true">15.97</preis>
<lieferant>Fa. Krause</lieferant>
</artikel>
...

odpovede:

1 pre odpoveď č. 1

Za predpokladu, že "artikel" by mal byť objednaný vopred, vložte xsl: sort do prvého príkazu xsl: for:

Niečo ako:

<xsl:for-each select="//lieferungen/artikel">
<xsl:sort select="preis" order="ascending"/>
<tr>

</tr>
</xsl:for-each>

Čo ste vyskúšali:

 <td><xsl:apply-templates><xsl:sort select="preis" order="ascending"/></xsl:apply-templates></td>

nefunguje, pretože aktuálny uzol je už "artikel". Šablóna xsl: apply-template sa vykonáva pre všetky deti (a atribúty) „artikel“.