找不到一个例子来解决很简单的情况。多个Xpath!=属性(不相等)排除表达式需要一个propper模式
所需的守则草案如下:
<xsl:template match="Document">
<Document>
<xsl:copy-of select="@*[name() !='attr-1']" /> <!-- the question is How to continue typing or rewrite this "Not Equal" expression adding multiple condition like !='attr-2', !='attr-3, !='attr-4', etc ?? (copy all attributes except (attr-1, attr-2, attr-3...) -->
<xsl:apply-templates/>
</Document>
</xsl:template>
</xsl:stylesheet>问题2:输出同样的结果会是这种表达方式的另一种\其他方式或风格吗?
发布于 2019-11-13 14:24:27
要复制列表中包含的属性以外的所有属性,可以方便地使用标识转换模板:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>并添加一个例外:
<xsl:template match="@attr-1 | @attr-2 | @attr-3"/>若要取消要省略的属性,请执行以下操作。
否则,您需要变得详细:
<xsl:copy-of select="@*[not(name() ='attr-1' or name() ='attr-2' or name() ='attr-3')]"/>注意使用not(a=b)而不是a!=b。
在XSLT2.0中,您可以使用except操作符来代替:
<xsl:copy-of select="@* except (@attr-1, @attr-2, @attr-3, @attr-4)"/>发布于 2019-11-13 17:36:44
你的问题的直接答案是not(name() = ('attr-1', 'attr-2', 'attr-3'))。但是,当您按名称有条件地处理事物时,在XSLT中通常有比对name()函数的结果进行字符串比较更好的方法。
https://stackoverflow.com/questions/58838974
复制相似问题