我遇到了xsl:foreach和select xpath
的问题<LIST>
<ELEMENT name="QX25">
<ELEMENT name="QX55A" value="1" />
<ELEMENT name="QX55B" value="2" />
<ELEMENT name="QX55C" value="xyz" />
<ELEMENT name="QX55D" value="dzy" />
</ELEMENT>
<ELEMENT name="QX55">
<ELEMENT name="QX55A" value="1" />
<ELEMENT name="QX55B" value="2" />
<ELEMENT name="QX55C" value="xyz" />
<ELEMENT name="QX55D" value="dzy" />
</ELEMENT>
<ELEMENT name="QX55">
<ELEMENT name="QX55A" value="2" />
<ELEMENT name="QX55B" value="1" />
<ELEMENT name="QX55C" value="dzy" />
<ELEMENT name="QX55D" value="xyz" />
<ELEMENT name="QX55E" value="X" />
</ELEMENT>
<ELEMENT name="QX55">
<ELEMENT name="QX55A" value="3" />
<ELEMENT name="QX55B" value="2" />
<ELEMENT name="QX55C" value="xyz" />
<ELEMENT name="QX55E" value="X" />
</ELEMENT>
<ELEMENT name="QX55">
<ELEMENT name="QX55A" value="4" />
<ELEMENT name="QX55B" value="3" />
<ELEMENT name="QX55C" value="xyz" />
<ELEMENT name="QX55E" value="P" />
</ELEMENT>
</LIST>
我希望获得名称为QX55的所有LIST / ELEMENT,其中没有名为=“QX55E”且值=“X”的子ELEMENT。 任何其他值都可以,并且没有名字=“QX55E”的子ELEMENT。
这意味着我希望得到以下结果:
<ELEMENT name="QX55">
<ELEMENT name="QX55A" value="1" />
<ELEMENT name="QX55B" value="2" />
<ELEMENT name="QX55C" value="xyz" />
<ELEMENT name="QX55D" value="dzy" />
</ELEMENT>
<ELEMENT name="QX55">
<ELEMENT name="QX55A" value="4" />
<ELEMENT name="QX55B" value="3" />
<ELEMENT name="QX55C" value="xyz" />
<ELEMENT name="QX55E" value="P" />
</ELEMENT>
我的尝试:
<xsl:for-each select="/LIST/ELEMENT[@name='QX55']/ELEMENT[not(@name='QX55E' and @value='X')]/../.">
有人可以帮忙吗?
答案 0 :(得分:2)
使用路径/LIST/ELEMENT[@name='QX55'][not(ELEMENT[@name = 'QX55E' and @value = 'X' ])]
。
答案 1 :(得分:1)
您可以使用count()函数:
<xsl:for-each select=" /LIST/ELEMENT[ @name='QX55' and count( ELEMENT[ @name='QX55E' and @value='X' ] ) = 0 ] " >