'XSLT: how to check if a subelement is equal to a value
I need to select all Message objects with subelement messageType='PrimaryMessage'.
I tried to do this via
<xsl:pattern matching="/">
<xsl:for-each select="...">
But I haven't been able to achieve the desired result yet. Can anyone help me?
Example XML:
<S:Envelope
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<QueryResultList>
<QueryResult>
<Message xsi:type="ResponseMessageType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<messageType>StatusMessage</messageType>
</Message>
</QueryResult>
<QueryResult>
<Message xsi:type="ResponseMessageType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<messageType>StatusMessage</messageType>
</Message>
</QueryResult>
<QueryResult>
<Message xsi:type="ResponseMessageType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<messageType>PrimaryMessage</messageType>
</Message>
</QueryResult>
</QueryResultList>
</S:Body>
</S:Envelope>
Solution 1:[1]
try the following:
<xsl:for-each select="QueryResultList/QueryResult/Message[messageType='PrimaryMessage']"/>
Basicly you add a filter to your expath expression. So instead of doing a for-each over all Message elements we only want Message elements where the child element messageType equals 'PrimaryMessage'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
