<xsl:apply-templates select="element[child='Yes']">
工作正常,但我想用XSLT - 在謂詞匹配的可變因素
<xsl:apply-templates select="element[$childElementName='Yes']">
,所以我可以用一個變量來指定節點。
例如
<xsl:apply-templates select="theList/entity[Central='Yes']">
工作正常反對:
<?xml version="1.0" encoding="utf-8"?>
<theList>
<entity>
<Business-Name>Company 1</Business-Name>
<Phone-Number>123456</Phone-Number>
<Central>Yes</Central>
<region1>No</region1>
<region2>Yes</region2>
<region3>No</region3>
<Northern>No</Northern>
</entity>
<entity>
<Business-Name>Company 2</Business-Name>
<Phone-Number>123456</Phone-Number>
<Central>No</Central>
<region1>Yes</region1>
<region2>No</region2>
<region3>No</region3>
<Northern>Yes</Northern>
</entity>
<entity>
<Business-Name>Company 3</Business-Name>
<Phone-Number>123456</Phone-Number>
<Central>Yes</Central>
<region1>No</region1>
<region2>No</region2>
<region3>No</region3>
<Northern>No</Northern>
</entity>
<entity>
<Business-Name>Company 4</Business-Name>
<Phone-Number>123456</Phone-Number>
<Central>No</Central>
<region1>No</region1>
<region2>No</region2>
<region3>No</region3>
<Northern>No</Northern>
</entity>
</theList>
但我不想硬編碼子元素的名稱。
有什麼建議嗎?
感謝蒂姆的回答:
<xsl:apply-templates select="theList/entity[child::*[name()=$childElement]='Yes']" />
會不選擇任何'entity'具有值爲「是」的後代節點實現相同的事情? – Oded 2010-07-27 06:22:27
好問題(+1)。看到我的答案是一個非常簡短的解決方案。 :) – 2010-07-27 13:07:48