首页 > 解决方案 > xsl 中“ends-with”语法的替代方案

问题描述

从这个来源引用

在 XSLT v1.0 中使用以结尾

ends-with 不适用于 XPATH 1.0,但我需要它的功能才能在我的应用程序上工作。

这是我需要匹配特定确切字符串的代码片段

<xsl:template match="p:Project/p:ItemGroup/p:Reference[starts-with(@Include, 'Common')]/@Include">

在该行中,我尝试将其修改为此以实现所需的输出,根据异常“ends-with syntax is not part of XPATH 1.0”

 <xsl:template match="p:Project/p:ItemGroup/p:Reference[starts-with(@Include, 'Common') and ends-with(@Include, 'Common') ]/@Include">

有没有其他方法可以做到这一点?

我需要做到这一点,因为要修改的xml文件中有部分以“Common”开头的字符串,如Common.UI,Common.Windows.Grid,所以在运行时,它也会影响这些行

它应该只改变一个只有“Common”的

标签: xmlxsltxslt-1.0

解决方案


该公式已在您提供的链接中说明。由于懒得分析,请测试以下内容:

<xsl:template match="p:Project/p:ItemGroup/p:Reference[starts-with(@Include, 'Common') and 'Common' = substring(@Include, string-length() - 5)]/@Include">

推荐阅读