Sort XML nodes in alphabetical order using XSL

前端 未结 1 548
旧时难觅i
旧时难觅i 2020-12-11 09:35

I am trying to figure out how to sort the XML list of employees alphabetically by lastname using XSL. Right now it just displays the XML information in the same order as it

相关标签:
1条回答
  • 2020-12-11 10:23

    At a glance,

        <xsl:sort select="Employee/Lastname" data-type="text" order="ascending"/>
        <xsl:sort select="Employee/Firstname" data-type="text" order="ascending"/>
    

    should be

        <xsl:sort select="Lastname" data-type="text" order="ascending"/>
        <xsl:sort select="Firstname" data-type="text" order="ascending"/>
    

    for-each sets the context node for the select, so the expression is evaluated against the Employee nodes.

    Also, text and ascending are defaults, so you could just write

        <xsl:sort select="Lastname"/>
        <xsl:sort select="Firstname"/>
    
    0 讨论(0)
提交回复
热议问题