首页 > 解决方案 > XSLT:检查字符串 A 是否包含标记化字符串 B 的任何元素

问题描述

我有一个分隔字符串source,我想知道它是否有任何标记化的子字符串target(也可以被标记化)。XSLT 函数过滤器是否提供此结果?

<xsl:variable name="source">2.0;2.1;2.2;2.3</xsl:variable>
<xsl:variable name="target">2.2;3.0</xsl:variable>
<xsl:variable name="source_tokenized">
    <xsl:value-of select="tokenize($source,';')"/>
</xsl:variable>
<xsl:value-of select="filter($source_tokenized ,contains($target,.))"/>

在此示例中,2.2包含在 中2.2;3.0,因此在这种情况下,源的标记之一确实包含在目标中。

当我收到一条消息时,我的语法不正确

static error near {...versions ,contains($target,...} in expression in xsl:value-of/@select on line 368 column 83 of stylesheet.xsl:
  XPST0017: Cannot find a 2-argument function named
  Q{http://www.w3.org/2005/xpath-functions}filter(). Higher-order functions are not
  available in this Configuration
Errors were reported during stylesheet compilation

标签: xslt

解决方案


我想知道它的任何标记化子字符串是否在目标中

这个表达式:

tokenize($target, ';') = tokenize($source, ';')

如果true()其中至少有一个令牌$target等于$source. 否则它将返回false()


推荐阅读