XSLT 2.0:检查节点集中的字符串是否包含在另一个字符串中

XSLT 2.0: Check if string within a node-set is contained in another string

我有一个要求,其中收到的输入 XML 对于相同的错误代码具有不同的错误描述。我需要比较部分文本是否包含在错误描述中,以便进行一些过滤。以下是我正在尝试做的事情的片段。

创建了一个变量来存储错误描述中要检查的所有部分文本的列表。

<xsl:variable name="partialTextList">
    <errorDesc value="insufficient funds" />
    <errorDesc value="amount cannot exceed" />
</xsl:variable>

创建了访问变量的密钥

<xsl:key name="kErrorDesc" match="errorDesc" use="@value" />

此 XSL 的输入 XML 将类似于

<Error>
    <Code>123</Code>
    <Desc>Transaction cannot be processed as account has insufficient funds.</Desc>
</Error>

<Error>
    <Code>123</Code>
    <Desc>The withdrawal amount cannot exceed account balance.</Desc>
</Error>

是否可以使用 contains 函数来检查 <Desc> 是否具有 partialTextList 中的值之一?

我试图为这个比较查找解决方案,但没有找到。大多数解决方案是检查列表中是否存在 <Desc> 值,反之亦然。

感谢任何帮助。

在例如xsl:template match="Error" 您当然可以检查 $partialTextList/errorDesc/@value[contains(current()/Desc, .)] 或将其移动到模式 xsl:template match="Error[$partialTextList/errorDesc/@value[contains(current()/Desc, .)]]" 如果您愿意。