当前位置: 动力学知识库 > 问答 > 编程问答 >

XPath AND operator with text() sequence

问题描述:

If the XML is defined by the following:

<xs:complexType name="Whatever" ....>

<xs:sequence>

<xs:element name="Tag" type="xs:string" minOccurs="0" maxOccurs="unbounded">

</xs:sequence>

</xs:complextType>

a document can contain:

<ns:Whatever>

<ns:Tag>hello</ns:Tag>

<ns:Tag>Peter</ns:Tag>

<ns:Tag>how are you</ns:Tag>

</ns:Watever>

or it could contain:

<ns:Whatever>

<ns:Tag>hello</ns:Tag>

</ns:Watever>

How does one write an XPath expression to find XML Whatever elements a union of Tag elements comparing the text() with an AND operator?

Writing /ns:Whatever[ns:Tag/text() = ('hello','Peter','how are you')] matches both above documents. I want to only match when the text of Tag is equal to 'hello' AND 'Peter' AND 'how are you'.

网友答案:

Hopefully your .xml contains typos.

You need the or operator not the and :

<xsl:value-of select="/ns:Whatever/ns:Tag[ . = 'hello' or . = 'Peter' or . = 'how are you']"/>
分享给朋友:
您可能感兴趣的文章:
随机阅读: