我不是很擅长xslt,以下是我的xslt
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="printJob">
<xsl:copy>
<xsl:apply-templates select="printDoc[@type!='adhoc']" />
<xsl:apply-templates select="printDoc[@type='adhoc']">
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
xslt的基本目的是转换xml,使所有printdoc元素属性@Type='adhoc'应该在父(printJob)列表中排在最后,所有其他元素应该检索它们现有的顺序。
我当前的xslt工作正常,当我的所有printDoc元素包含"Type"属性,但在某些xml中,"Type"printDoc"属性缺失
元素。如果您确实使用XSLT 2,正如代码中的版本所建议的那样,那么我认为您的需求的字面实现将是简单地使用
<xsl:apply-templates select="* except printDoc[@type='adhoc'], printDoc[@type='adhoc']"/>
XSLT 3示例(可以用XSLT 2的标识模板替换xsl:mode
声明)。
<xsl:apply-templates select="*[not(self::printDoc[@type='adhoc'])]"/>
<xsl:apply-templates select="printDoc[@type='adhoc']"/>