@JohnBollinger和@MartinHonnen正确地指出
@*
条件将插入所有属性,甚至是上面选择的属性。因此,必须改进条件。还指出,根据规范,无法确保属性的顺序。事实上
是
被订购只是我的处理器(Saxon9-HE)如何工作的产物。不过我对这个没意见。以下是我得出的解决方案:
<xsl:template match="xsd:attribute">
<xsl:copy>
<xsl:copy-of select="@name" />
<xsl:copy-of select="@type" />
<xsl:copy-of select="@ref" />
<xsl:copy-of select="@use[string() != 'optional']" />
<xsl:copy-of select="@default" />
<xsl:apply-templates select="@*[name(.) != 'use']">
<xsl:sort select="name()" />
</xsl:apply-templates>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
我没有将其他属性名称添加到
@*
因为Saxon不会复制属性并按要求的顺序保留它们,即使它是由
@*
条款因此,这确实以最少的努力满足了我目前的需求,即使它不是一个通用的解决方案(我实际上并不需要)。