次のような文字列内の単語を見つける関数を作成したい
word(@class, 'items')
に等しくなります
fn:matches(@class, "(^|\s)items(\s|$)")
これを行うにはさまざまな方法がありますが、最も簡単な解決策は、言語内で関数を定義できる XQuery を使用することです。
declare function local:word($a as xs:string, $b as xs:string) as xs:boolean {
matches($a, concat("(^|\s)", $b, "(\s|$)"))
};
XSLT 2.0で見つけたもの
<x:transform version="2.0"
xmlns:x="http://www.w3.org/1999/XSL/Transform"
xmlns:find="http://user.com/namespace">
<x:output method="html"/>
<x:function name="find:word">
<x:param name="src"/>
<x:param name="word"/>
<x:sequence select="matches($src, concat('(^|\s)', $word, '(\s|$)'))"/>
</x:function>
<x:template match="//*[find:word(@class, 'items')]">
<x:copy>
<x:copy-of select="@*"/>
</x:copy>
</x:template>
</x:transform>