問題は、関数内にあまりにも多くの式をラップしていることですconcat()
。それが評価されると、REGEX 一致式に動的文字列を使用する XPath 式を評価するのではなく、XPath 式となる文字列を返します。
使用したい:
<xsl:value-of select="$di:meta[matches(@domain
,concat('.*('
,current()
,').*')
,'i')][1]" />
ただし、各用語を個別に評価しているため、これらの各用語を単一の正規表現パターンに入れて最初の用語を選択するのではなく、一致したシーケンスの最初の結果ではなく、各一致の最初の結果を返すようになりました。アイテム。それはあなたが望むものかもしれませんし、そうでないかもしれません。
一致したアイテムのシーケンスから最初のアイテムが必要な場合は、次のようにすることができます。
<!--Create a variable and assign a sequence of matched items -->
<xsl:variable name="matchedMetaSequence" as="node()*">
<!--Iterate over the sequence of names that we want to match on -->
<xsl:for-each select="tokenize($csvString,',')">
<!--Build the sequence(list) of matched items,
snagging the first one that matches each value -->
<xsl:sequence select="$di:meta[matches(@domain
,concat('.*('
,current()
,').*')
,'i')][1]" />
</xsl:for-each>
</xsl:variable>
<!--Return the first item in the sequence from matching on
the list of domain regex fragments -->
<xsl:value-of select="$matchedMetaSequence[1]" />
これを次のようにカスタム関数に入れることもできます。
<xsl:function name="di:findMeta">
<xsl:param name="meta" as="element()*" />
<xsl:param name="names" as="xs:string" />
<xsl:for-each select="tokenize(normalize-space($names),',')">
<xsl:sequence select="$meta[matches(@domain
,concat('.*('
,current()
,').*')
,'i')][1]" />
</xsl:for-each>
</xsl:function>
そして、次のように使用します。
<xsl:value-of select="di:findMeta($di:meta,'foo,bar,baz')[1]"/>