xslt-2.0 - XSLT 2.0:检查节点集中的字符串是否包含在另一个字符串中
问题描述
我有一个要求,其中接收到的输入 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>
列表中是否存在值,反之亦然。
任何帮助表示赞赏。
解决方案
在 eg 的上下文中,xsl:template match="Error"
您当然可以根据需要检查$partialTextList/errorDesc/@value[contains(current()/Desc, .)]
或将其移动到模式中xsl:template match="Error[$partialTextList/errorDesc/@value[contains(current()/Desc, .)]]"
。
推荐阅读
- sas - 如何格式化 proc 表格以产生十进制数百万?
- sql - 在嵌套的一对多关系表上解决 N+1 休眠问题
- macos - 设置可执行文件的权利
- javascript - 当我的 webapp 收到来自 firebase 的消息时,XMLHttpRequest 不能在 messing.setBackgroundMessageHandler(...) 中用于接收反馈
- instagram-api - Instagram API 数据与 Instgram Insights 数据不匹配
- aws-api-gateway - API Gateway 响应 403 而不是 404
- c# - Func<> 作为函数的可选参数必须是编译时间常数吗?
- javascript - 使用同一个音频对象时多次播放 JavaScript 音频
- c - C - 使用指针时出现 strncpy 段错误
- java - 如何在 Amazon-ECS 实例之间共享连接池