英文:
XSLT 2.0: Check if string ends with a value from an array
问题
如何检测一个字符串是否以预先确定的数组中的某个值结尾?
从其他在SO上的问题中自己无法弄清楚,因为它们问的是完全匹配的字符串。
类似这样的:
<xsl:template match="card">
<xsl:variable name="word" select="k" />
<xsl:variable name="obviouslyRussianSuffixes" select="('изм', 'ия', 'ист', 'ёр', 'ца', 'фон')" />
<xsl:if test="ends-with($word, $obviouslyRussianSuffixes)">
<xsl:value-of select="$word" />
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
英文:
How can I detect that a string ends with a value from a pre-determined array?
Couldn't figure it out myself from other questions on SO because they ask about a complete string match.
Something like this
<xsl:template match="card">
<xsl:variable name="word" select="k" />
<xsl:variable name="obviouslyRussianSuffixes" select="('изм', 'ия', 'ист', 'ёр', 'ца', 'фон')" />
<xsl:if test="ends-with($word, $obviouslyRussianSuffixes)">
<xsl:value-of select="$word" />
<xsl:text>&#xa;</xsl:text>
</xsl:if>
</xsl:template>
答案1
得分: 2
我认为你希望测试为some $suffix in $obviouslyRussianSuffixes satisfies ends-with($word, $suffix)
。
英文:
I think you want the test to be some $suffix in $obviouslyRussianSuffixes satisfies ends-with($word, $suffix)
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论