XSLT 2.0:检查字符串是否以数组中的某个值结尾

huangapple go评论60阅读模式
英文:

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>&#xa;</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

&lt;xsl:template match=&quot;card&quot;&gt;
    &lt;xsl:variable name=&quot;word&quot; select=&quot;k&quot; /&gt;
    &lt;xsl:variable name=&quot;obviouslyRussianSuffixes&quot; select=&quot;(&#39;изм&#39;, &#39;ия&#39;, &#39;ист&#39;, &#39;ёр&#39;, &#39;ца&#39;, &#39;фон&#39;)&quot; /&gt;
    &lt;xsl:if test=&quot;ends-with($word, $obviouslyRussianSuffixes)&quot;&gt;
        &lt;xsl:value-of select=&quot;$word&quot; /&gt;
        &lt;xsl:text&gt;&amp;#xa;&lt;/xsl:text&gt;
    &lt;/xsl:if&gt;
&lt;/xsl:template&gt;

答案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).

huangapple
  • 本文由 发表于 2023年1月9日 01:03:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定