xml - xsl排序不排序?

标签 xml xslt

lecturer.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="html" version="4.0"/>
        <xsl:template match="/">
            <html>
            <head>
                <title>Lecturer Information</title>
            </head>
            <body>  

                <table border="1">

                    <tr bgcolor="#9acd32">
                        <th>Name</th>
                        <th>Teaching</th>
                        <th>Research</th>
                    </tr>

                    <xsl:for-each select="lecturers/lecturer">
                        <tr>
                            <td>
                                <xsl:apply-templates select="name">
                                     <xsl:sort select="@last" data-type="text" order="descending"/>
                                </xsl:apply-templates>
                            </td>
                            <td><xsl:apply-templates select="teaching/course" /></td>
                            <td><xsl:value-of select="research"/></td>
                        </tr>
                    </xsl:for-each>

                </table>

            </body>
        </html>
    </xsl:template>

    <!-- Templates HERE -->
    <xsl:template match="name">
        <xsl:value-of select="@title"/><xsl:text> </xsl:text>
        <xsl:value-of select="@first"/><xsl:text> </xsl:text>
        <xsl:value-of select="@last"/>
    </xsl:template>

    <xsl:template match="teaching/course">
        <xsl:for-each select=".">
                <xsl:value-of select="concat(. , '(',@code, ')')"/>  <br />
            <!-- <xsl:value-of select="."/> (<xsl:value-of select="@code"/>) -->
        </xsl:for-each>
    </xsl:template>


</xsl:stylesheet>

lecturer.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lecturer.xsl" ?>

<!DOCTYPE lecturers [

<!ELEMENT lecturers (lecturer+)>
<!ELEMENT lecturer (name, teaching, research)>

 <!-- Element name must contain attribute title, first and last -->
<!ELEMENT name (#PCDATA)>
<!ATTLIST name
  title CDATA #REQUIRED
  first CDATA #REQUIRED
  last CDATA #REQUIRED
>

<!-- Teaching can have more than one course-->
<!ELEMENT teaching (course+)>

<!ELEMENT course (#PCDATA)>
<!ATTLIST course
    code CDATA #REQUIRED
>

<!ELEMENT research (#PCDATA)>

]>
<lecturers>
    <lecturer>
        <name title="Professor" first="Peter" last="Quirk"/>
        <teaching>
                <course code="CO3070">XML and the Web</course>
                <course code="CO3300">Web Server Architectures</course>
        </teaching>
        <research>
                The application of Web protocols to Biology
        </research>
    </lecturer>
    <lecturer>
        <name title="Mr" last="Abdi" first="Ahmet"/>
        <teaching>
                <course code="CO1337">Ahmet's Course</course>
        </teaching>
        <research>
                The Best Research In the world.
        </research>
    </lecturer>
</lecturers>

这部分xsl好像没有排序

<xsl:sort select="@last" data-type="text" order="descending"/>

最佳答案

相信行

<xsl:sort select="name/@last" data-type="text" order="descending"/>

需要在for-each语句下面

<xsl:for-each select="lecturers/lecturer">

这应该按姓氏对所有讲师进行排序。

关于xml - xsl排序不排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13495018/

相关文章:

xml - VBA XML 解析——遍历子节点

javascript - 如何使用node.jsexpress响应XML?

xslt - 使用相同的输入和输出文件使用 ant xslt 任务

java - JAXB 没有为包含生成的 Java 类的类生成所需的模式?

Java 正则表达式到 xml

c# - 如何构建自定义 AngleSharp 元素并将 HTML 部分插入/转换到元素中

c# - Umbraco 在 xslt 中发布日期

javascript - 将用户输入传递到 XSL 样式表

c# - 在 .NET 6 中使用 xsltc.exe 生成的程序集(XSLT 样式表)

xml - XSLT:如何从某个目录获取文件名?