我有一个xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<success>0</success>
<success>0</success>
<success>1</success>
</soapenv:Body>
我想实现这样的逻辑:如果成功标签之一等于 0,则返回 true;如果所有成功标签都等于 0,则返回 false。
到目前为止,我已经做到了,但我不知道如何使 xslt 重新调整 errorFlag=false(如果它们全部为 =0):
<xsl:template match="/">
<xsl:call-template name="test" />
</xsl:template>
<xsl:template match="/soapenv:Envelope/soapenv:Body" name ="test">
<errorFlag>
<xsl:if test="contains(.,'0')">true</xsl:if>
</errorFlag>
</xsl:template>
想要的输出 - 只有一个字段:
<errorFlag>true<errorFlag> (if all are success=0)
怎么样:
<xsl:template match="/">
<errorFlag>
<xsl:value-of select="not(/soapenv:Envelope/soapenv:Body/success=1)" />
</errorFlag>
</xsl:template>
或者(需要 XSLT 2.0):
<xsl:template match="/">
<errorFlag>
<xsl:value-of select="every $item in /soapenv:Envelope/soapenv:Body/success satisfies $item=0"/>
</errorFlag>
</xsl:template>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)