XSLT选择子节点中存在值的父节点
问题描述:
如何选择'消息'节点,其中任何子节点的值为'EXCEPTION'。XSLT选择子节点中存在值的父节点
<?xml version="1.0" encoding="UTF-8"?>
<Envelope>
<Message>
<MessageId>1</MessageId>
<Merchant>
<Type>Supplier</Type>
<Id>23</Id>
</Merchant>
<Operation>Create</Operation>
<SKU>AVRCD_002</SKU>
<Attribute>
<country>South Africa</country>
<artist>Anneli Van Rooyen</artist>
<composer>Anneli Sale</composer>
</Attribute>
</Message>
<Message>
<MessageId>2</MessageId>
<Merchant>
<Type>Supplier</Type>
<Id>EXCEPTION</Id>
</Merchant>
<Operation>Create</Operation>
<SKU>AVRCD_002</SKU>
<Attribute>
<country>EXCEPTION</country>
<artist>Anneli Van Rooyen|Lorenzo Tieghi</artist>
<composer>Sale Anneli</composer>
</Attribute>
</Message>
</Envelope>
下面你需要指定确切的孩子。我不想这样做。我只是想/如果任何内容中有'EXCEPTION'的值。
<xsl:copy-of select="/Envelope/Message[Attribute/country = 'EXCEPTION' or Merchant/Id = 'EXCEPTION']"/>
答
试试这个,以查找所有后代文本节点等于“EXCEPTION”
<xsl:copy-of select="/Envelope/Message[.//text() = 'EXCEPTION']"/>
完美的感谢,我得到接近,但不可能得到它100% –
但要小心,@ LorenzoTieghi,因为一个节点作为字符串值为“EXCEPTION”的文本节点的父节点不一定与该节点的* own *字符串值为“EXCEPTION”相同。混合内容的元素可能会出现差异。前者可能确实是你想要的,但你应该对此满足。 –