xslt 2.0 を使用して Saxon-ce で ixsl:eval() を使用して動的 xpath を評価しようとしていますが、機能していないようです。これが例示的なXMLです
<things>
<thing>
<name>widget one</name>
<number>10</number>
<type>metal</type>
<subtypes>
<subtype>red<subtype>
</subtypes>
</thing>
<thing>
<name>widget two</name>
<number>11</number>
<type>wood</type>
<subtypes>
<subtype>red</subtype>
<subtype>blue</subtype>
</subtypes>
</thing>
</things>
そして、私が評価しようとしているxsl 2.0スタイルシートの一部(さまざまなパラメータが、より大きなxslスタイルシートの別の部分によって渡されます)
<template name="display" match="things">
<xsl:param name="num"/>
<xsl:param name="type" as="xs:string"/>
<xsl:param name="subtype" as="xs:string"/>
<xsl:variable name="xpathExp" as="xs:string">
<xsl:text>things/thing</xsl:text>
<xsl:if test="not($num = 'all')>
<xsl:copy-of select="concat('[number=',$num,']')"/>
</xsl:if>
<xsl:if test="not($type = 'all')>
<xsl:copy-of select="concat('[type=''',$type,''']')"/>
</xsl:if>
<xsl:if test="note($subtype = 'all')>
<xsl:copy-of select="concat('[subtype/subtypes=''',$subtype,''']')/>
</xsl:if>
</xsl:variable>
<xsl:result-document href="#display" method="ixsl:replace-content">
<xsl:for-each select="ixsl:eval($xpathExp)">
<xsl:sort select="name"/>
</xsl:for-each>
</template>
eval ステートメントを明示的な xpath ステートメントに置き換えると、コードが機能するため、何らかの理由で $xpathExp の eval が機能しません。アイデア?
* 編集 * これはより良い XML の例です:
<things>
<thing>
<name>widget one</name>
<number>10</number>
<type>metal</type>
<subtypes>
<subtype>red<subtype>
</subtypes>
</thing>
<thing>
<name>widget two</name>
<number>11</number>
<type>wood</type>
<subtypes>
<subtype>red</subtype>
<subtype>blue</subtype>
</subtypes>
</thing>
<thing>
<name>widget three</name>
<number>11</number>
<type>metal</type>
<subtypes>
<subtype>blue</subtype>
</subtypes>
</thing>
</things>
ユーザーは、数値、タイプ、およびサブタイプのドロップボックスを介して値を選択できます。ユーザーの選択に応じて、モノの名前のリストが表示されます。たとえば、ユーザーが数字の 11 とサブタイプの赤を選択すると、ウィジェット 2 が表示されます。代わりに青のサブタイプを選択すると、ウィジェット 2 と 3 の名前が表示されます。
したがって、基本の xpath フィルターは things/thing です。ユーザーが数値を選択した場合、xpath 式に [number=$num] を追加したいので、ti は things/thing[number=$num] になります。彼らが複数のアイテムを選択した場合、たとえば番号とタイプ、[number=$num][type=$type] がベース xpath に追加され、things/thing[number=$num][type=$] が追加されますタイプ]。
基本的に私が避けようとしているのは、可能なすべての順列と可能なユーザー選択の組み合わせを個別にコーディングする必要があることです。
それは役に立ちますか?