【发布时间】:2023-01-11 00:52:46
【问题描述】:
我对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,以便所有打印文档具有属性的元素@Type='临时'应该在它们的父(printJob)列表中排在最后,所有其他元素应该检索它们现有的顺序。
当我所有的 printDoc 元素都包含“Type”属性时,我当前的 xslt 工作正常,但在某些 xml 中,“printDoc”元素缺少“Type”属性。
【问题讨论】:
-
[@Type!='adhoc']表示必须有一个Type属性,其值不是adhoc。[not(@Type='adhoc')]还涵盖了没有Type属性的情况。