1
XML輸入:XML排序FN不工作如下
<Global>
<ProductFood>
<foodName>Burger</foodName>
<foodName>Snack</foodName>
</ProductFood>
<ProductToy>
<Product ProductID="1">
<productName>Doll</productName>
<Color>Green</Color>
</Product>
<Product ProductID="2">
<productName>Ball</productName>
<Color>White</Color>
</Product>
</ProductToy>
</Global>
XSLT的代碼,我有低於:
<xsl:template match="//Products">
<html>
<body>
<Products>
<xsl:apply-templates select="ProductToy" >
<xsl:sort select="@name"/>
<xsl:apply-templates/>
</Products>
</body>
</html>
</xsl:template>
<xsl:template match="Product">
<xsl:element name="product">
<xsl:attribute name="name" select="ProductName/text()" />
<xsl:element name="productID">
<xsl:value-of select="@ProductID" />
</xsl:element>
</xsl:element>
</xsl:template>
我想輸出返回產品由升屬性名稱但我的排序不起作用,因爲它仍然顯示產品球,然後只有娃娃。請告訴如何使其工作。
您正在存儲ProductToy元素,但只有一個ProductToy元件;僅使用一個元素對一個集合進行排序不是一個非常有用的操作。此外,您正在按名稱屬性的值排序它們,但您的ProductToy元素和其他任何內容都沒有名稱屬性。 –