xsl:sort with apply-templates not sorting

前端 未结 2 1543
一整个雨季
一整个雨季 2021-01-04 10:42

I have quite a large XSL document for an assignment that does a number of things. It is nearly complete but I missed a requirement that it has to be sorted and I cannot get

相关标签:
2条回答
  • 2021-01-04 11:29

    what is missing is a staff matching template or change the matching template to member like in this one:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <!--   Root Document    -->
    <xsl:template match="/">
    
        <html>
        <body>
    
            <xsl:apply-templates select="staff/member">
                <xsl:sort select="last_name" />
            </xsl:apply-templates>
    
        </body>
        </html>
    
    </xsl:template>
    
    <xsl:template match="member">
        <xsl:value-of select="first_name" />&#160;<xsl:value-of select="last_name" /> <br/>
    </xsl:template>
    
    </xsl:stylesheet>
    
    0 讨论(0)
  • 2021-01-04 11:32
        <xsl:apply-templates select="staff">
            <xsl:sort select="member/last_name" />
        </xsl:apply-templates>
    

    selects the staff elements and sorts them, but there is only one staff element, so this is a no-op.

    Change to

        <xsl:apply-templates select="staff/member">
            <xsl:sort select="last_name" />
        </xsl:apply-templates>
    

    then that selects all the member elements and sorts them.

    0 讨论(0)
提交回复
热议问题