【问题标题】:XSLT 2.0: Check if string within a node-set is contained in another stringXSLT 2.0:检查节点集中的字符串是否包含在另一个字符串中
【发布时间】:2021-06-17 17:05:47
【问题描述】:

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

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

<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 函数来检查&lt;Desc&gt; 是否具有来自partialTextList 的值之一?

我试图为这种比较查找解决方案,但找不到。大多数解决方案是检查&lt;Desc&gt; 值是否存在于列表中,反之亦然。

感谢任何帮助。

【问题讨论】:

    标签: xslt-2.0 xslkey


    【解决方案1】:

    在例如的上下文中xsl:template match="Error" 你当然可以检查$partialTextList/errorDesc/@value[contains(current()/Desc, .)] 或者如果你喜欢把它移到模式xsl:template match="Error[$partialTextList/errorDesc/@value[contains(current()/Desc, .)]]"

    【讨论】:

    • 完美。谢谢你的建议。我想我正在考虑使用键的完全不同的路线。
    猜你喜欢
    • 2013-03-13
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多