正确的模板是
<xsl:template match="employees">
<xsl:copy>
<xsl:apply-templates select="employee">
<xsl:sort select="@lastname"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
然后您需要确保设置了身份转换,当前版本的 XSLT 3.0 是
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="employees">
<xsl:copy>
<xsl:apply-templates select="employee">
<xsl:sort select="@lastname"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>