【发布时间】:2020-03-31 16:20:40
【问题描述】:
下午好,
我有以下 XML 作为输入:
<?xml version="1.0" encoding="UTF-8"?>
-<S:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
-<S:Header>
-<wsse:Security S:mustUnderstand="1">
-<wsu:Timestamp wsu:Id="_1" xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns15="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<wsu:Created>2020-03-27T19:04:20Z</wsu:Created>
<wsu:Expires>2020-03-27T19:09:20Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</S:Header>
-<S:Body>
-<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>Ocorreu um erro no serviço</faultstring>
-<detail>
-<ns3:DataLicensingFault xmlns:ns3="http://services.experian.com.br/DataLicensing/DataLicensingService/" xmlns:ns2="http://www.experian.com.br/schema/infocleanws">
<codeReason>100</codeReason>
<reason>Parâmetro cnpj é inválido.</reason>
</ns3:DataLicensingFault>
</detail>
</S:Fault>
</S:Body>
</S:Envelope>
我需要获取在 codeReason 标记中找到的值。
为此,我使用以下命令
<xsl: variable name = "vCodeReason" select = "./ soapenv: Fault / detail / DataLicensingFault / codeReason" />
但我得到了 vCodeReason 变量的白色值。
正确的做法是让我得到值 100。
我正在发送 xslt 程序:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<!-- Campos do Datatype da Interface :-->
<xsl:variable name="vFaultCode" select="./soapenv:Fault/faultcode"/>
<xsl:variable name="vFaultString" select="./soapenv:Fault/faultstring"/>
<xsl:variable name="vCodeReason" select="./soapenv:Fault/detail/DataLicensingFault/codeReason"/>
<xsl:variable name="vReason" select="./soapenv:Fault/detail/DataLicensingFault/reason"/>
<xsl:choose>
<xsl:when test="$vFaultCode!=''">
<ns0:ConsultarPJResponse xmlns:ns0="http://services.experian.com.br/DataLicensing/DataLicensingService/">
<result>
<situacaoCadastral>
<codigoSituacao>
<xsl:value-of select="$vCodeReason"/>
</codigoSituacao>
<situacao>
<xsl:value-of select="$vFaultString"/>
</situacao>
</situacaoCadastral>
</result>
</ns0:ConsultarPJResponse>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="/"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
你能帮帮我吗?
【问题讨论】:
-
请发布minimal reproducible example,以便我们在定义变量时查看当前上下文。注意
DataLicensingFault在命名空间中,所以在引用它时必须使用前缀。 -
对不起。我正在发送 xslt 程序