Reputation: 99
I have a soap message
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<id>0</id>
<id>1</id>
</soapenv:Body>
</soapenv:Envelope>
I want to loop through the id elements and check if the current one has a value = 1 but my xslt is not working.
<xsl:template match="/">
<xsl:for-each select="node()">
<xsl:if test="current()/text='1'">
do something
</xsl:if>
</xsl:for-each>
</xsl:template>
Can someone point out what I do wrong and give me directions on how to proceed?
EDIT: I need something that will return true when one of id's is equal to 1, otherwise false .
Upvotes: 0
Views: 87
Reputation: 117100
I want to loop through the id elements and check if the current one has a value = 1
You don't need to do that. The following expression:
/soapenv:Envelope/soapenv:Body/id=1
will return true
if one or more of the id
elements has the value of 1, false
otherwise.
Demo: https://xsltfiddle.liberty-development.net/ej9EGc8
Upvotes: 1
Reputation: 461
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="soapenv:Envelope">
<xsl:for-each select="soapenv:Body">
<xsl:if test="id='1'">
do something
</xsl:if>
</xsl:for-each>
</xsl:template>
You may use like this
Upvotes: 1