<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:config="http://tempuri.org/config"
exclude-result-prefixes="config"
>
<config:categories>
<value>600</value>
<value>605</value>
<value>610</value>
</config:categories>
<xsl:variable
name = "vCategories"
select = "document('')/*/config:categories/value"
/>
<xsl:key
name = "kPropertyByLabel"
match = "Properties/LabeledProperty/Value"
use = "../Label"
/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="key('kPropertyByLabel', 'Category Code') = $vCategories">
<!-- ... -->
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
これが機能するのは=
、ノードセットで作業するときに、XPathオペレーターが左側のすべてのノードを右側のすべてのノードと比較するためです(SQLと比較してINNER JOIN
)。
したがって、必要なのは、個々の値からノードセットを作成することだけです。一時的な名前空間を使用すると、XSLTファイルでそれを行うことができます。
<xsl:key>
また、ラベルによるプロパティ値の選択をより効率的にするためにを導入したことにも注意してください。
編集:外部config.xml
ファイルを作成してこれを行うこともできます:
<xsl:variable name="vConfig" select="document('config.xml')" />
<!-- ... -->
<xsl:when test="key('kPropertyByLabel', 'Category Code') = $vConfig/categories/value">
XSLT 2.0では、シーケンスの概念が追加されました。そこで同じことをする方が簡単です。
<xsl:when test="key('kPropertyByLabel', 'Category Code') = tokenize('600,605,610', ',')">
'600,605,610'
これは、文字列を外部パラメータとして簡単に渡すことができることを意味します。