0
我有以下輸入XML:對_any_子節點使用'contains' - 只匹配第一個孩子?
<relations>
<parent>
<child>a</child>
<child>b</child>
<child>c></child>
</parent>
<parent>
<child>x</child>
<child>y</child>
<child>z></child>
</parent>
</relations>
而我感興趣的只是在處理其子節點(任何人)的含有特定字符串「父」節點;我創建了以下XSLT(1.0) - 但這顯然只對第一個孩子應用'contains'函數?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:apply-templates select="relations" />
</xsl:template>
<xsl:template match="relations">
<xsl:apply-templates select="parent[ contains(child, 'a') ]" />
</xsl:template>
<xsl:template match="parent">
<xsl:text>FOUND A MATCH, </xsl:text>
</xsl:template>
</xsl:stylesheet>
那就是:如果我不過是一個「A」或「X」「包含」功能爲我輸入的文件,我得到一個匹配,但如果我把一個「B」,「C」 ,'y'或'z' - 它不再返回true。
如何重新編寫這個匹配項,當任何孩子匹配包含?
謝謝 - 證實了這一工作:我測試「 b'(這是一個孩子)和'h'(不是) - 結果證實了這一點。我在等SOF計時器讓我接受答案。 – monojohnny