0

次のような文字列内の単語を見つける関数を作成したい

word(@class, 'items')

に等しくなります

fn:matches(@class, "(^|\s)items(\s|$)")
4

2 に答える 2

1

これを行うにはさまざまな方法がありますが、最も簡単な解決策は、言語内で関数を定義できる XQuery を使用することです。

declare function local:word($a as xs:string, $b as xs:string) as xs:boolean {
  matches($a, concat("(^|\s)", $b, "(\s|$)"))
};
于 2013-03-28T22:43:31.250 に答える
0

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>
于 2013-03-29T18:20:12.860 に答える