以下工作:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match=
"*[ID='579']/EMAIL"/>
</xsl:stylesheet>但我需要删除基于许多ID值的电子邮件元素,如下所示:
"*[ID='579|987|1023']/EMAIL"/>你怎么用xslt-3更聪明地做这件事?
发布于 2022-07-01 09:47:04
使用字符串序列参数。
<xsl:param name="ids" as="xs:string*" select="'579', '987', '1023'"/>那么您可以使用match="*[ID = $ids]/EMAIL"
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:param name="ids" as="xs:string*" select="'579', '987', '1023'"/>
<xsl:template match="*[ID = $ids]/EMAIL"/>
</xsl:stylesheet>或传入用|分隔并使用match="*[ID = tokenize($ids, '\|')]/EMAIL"的单个字符串。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:param name="ids" as="xs:string" select="'579|987|1023'"/>
<xsl:template match="*[ID = tokenize($ids, '\|')]/EMAIL"/>
</xsl:stylesheet>https://stackoverflow.com/questions/72827089
复制相似问题