我使用的是XSLT一塊XML,如排序:XSLT:排序像SOLR
<feed>
<entry>
<title>A To Z</title>
</entry>
<entry>
<title>Action</title>
</entry>
</feed>
的XSLT的樣子:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="name" select="'title'" />
<xsl:param name="order" select="'ascending'" />
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="atom:feed">
<xsl:copy>
<xsl:apply-templates select="/atom:feed/*[not(self::atom:entry)]" />
<xsl:apply-templates select="/atom:feed/atom:entry">
<xsl:sort select="*[name() = $name]" order="{$order}" />
<xsl:sort select="atom:id" data-type="number" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我預計值的出來順序如A到Z,然後是Action,但結果卻包含相反的結果。它看起來像被忽略的空白作爲排序的值。
@smokedice我刪除了一些未使用的參數和名稱空間,以使XSLT更易於閱讀。評論或編輯,如果你覺得這些對於問題很重要 – phihag 2011-01-26 12:10:36
@smokedice:似乎爲我工作,它是如何失敗? – Lazarus 2011-01-26 12:19:35
問題是生成的第一個標題是Action,然後是A到Z. @Lazarus是否使用Xerces來應用模板? – smokedice 2011-01-26 12:23:40