current()
I.キーと:)を使用したもう1つのソリューション:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kItemByProp" match="item"
use="boolean(/*/properties/property/@id
[contains(concat(' ', current()/@properties, ' '),
.)]
)"/>
<xsl:template match=
"item[count(.| key('kItemByProp', 'true'))
=
count(key('kItemByProp', 'true'))
]
">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
この変換が提供された XML ドキュメントに適用されると、次のようになります。
<t>
<items>
<item id='a' properties='red little' />
<item id='b' properties='big strong heavy' />
<item id='c' properties='blue heavy' />
</items>
<properties>
<property id='red' />
<property id='little' />
<property id='blue' />
</properties>
</t>
必要な正しい結果が生成されます。
<item id="a" properties="red little"/>
<item id="c" properties="blue heavy"/>
Ⅱ.キーはありませんが、テンプレート本体の最も外側に条件付き命令があります。
<xsl:template match="item">
<xsl:if test=
"/*/properties/*/@id
[contains(concat(' ', current()/@properties, ' '), .)]">
<!-- Your processing here -->
</xsl:if>
</xsl:template>
完全な変換は次のとおりです。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="item">
<xsl:if test=
"/*/properties/*/@id
[contains(concat(' ', current()/@properties, ' '), .)]">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
この変換を同じ XML ドキュメント (上記) に適用すると、同じ正しい結果が生成されます。
<item id="a" properties="red little"/>
<item id="c" properties="blue heavy"/>