现在的位置: 首页 > 综合 > 正文

关于XSL中xsl:for-each的order-by属性的使用

2018年05月09日 ⁄ 综合 ⁄ 共 883字 ⁄ 字号 评论关闭

 在XML的教学中无意中发现有时候xsl:for-each的order-by属性不可用,经过测试发现是命名空间的问题。

当这样声明时,order-by属性可用

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

而当使用如下声明时,order-by属性不可用

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

原来order-by是XML草案中的内容,在正式版本中已经取消了它,而是以xsl:sort取而代之。

例如以下代码片断:

          <xsl:for-each select="students/student" order-by="phone">
           <tr>
                <td><xsl:value-of select="name"/></td>
                <td><xsl:value-of select="phone"/></td>
                <td><xsl:value-of select="birthday"/></td>
           </tr>
            </xsl:for-each>

应改写为以下形式:

            <xsl:for-each select="students/student">
            <xsl:sort select="phone"/>
           <tr>
                <td><xsl:value-of select="name"/></td>
                <td><xsl:value-of select="phone"/></td>
                <td><xsl:value-of select="birthday"/></td>
           </tr>
            </xsl:for-each>

抱歉!评论已关闭.