2013-07-17 48 views
0

我已經寫了一個XSLT的塊,我想排序我的XML文件,但那不工作。你能告訴我我該如何解決這個問題,以及爲什麼這個代碼不適合我。 Thenk你這麼多的幫助xslt排序不工作在xslt

我的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> 

和XML是:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet type="text/xsl" href="C:\Users\Babak\Desktop\XSLT\sort.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> 
... 

回答

1

假設 「ARTIKEL」 應該由PREIS下令放了xsl:排序爲第一聲明到您的xsl:for:

喜歡的東西:

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

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

你嘗試過什麼:

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

不起作用,因爲當前節點已經是 「ARTIKEL」。 xsl:apply-templates爲「artikel」的所有子項(和屬性)完成。