XSLT 创建仅节点字段存在



我有一个要求,只有当其中一个元素(sequenceNumber(存在时,我才需要考虑节点(节点名称:LineItem(,剩下的所有行项目我们需要删除。 我在下面尝试过,但它不起作用。

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LineItem[sequenceNumber]"/>
</xsl:stylesheet>``

而不是<xsl:template match="LineItem[sequenceNumber]"/>我认为你想要<xsl:template match="LineItem[not(sequenceNumber)]"/>或者,根据您的评论,如果另一个元素可以作为后代出现,你需要<xsl:template match="LineItem[not(.//sequenceNumber)]"/>.

尝试使用 xsl:选择

<xsl:template match="LineItem">
<xsl:choose>
<xsl:when test=".//sequenceNumber">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise>
<!-- skip element -->
</xsl:otherwise>
<xsl:choose>
</xsl:template>

最新更新