0

I have the response below from an WS

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="XX" xmlns:ns2="XX">
    <SOAP-ENV:Body>
        <ns2:entregarManifestacaoProcessualResposta>
            <ns1:sucesso>true</ns1:sucesso>
            <ns1:mensagem>Some strange error messafe</ns1:mensagem>
            <ns1:protocoloRecebimento>XXXXXXXX</ns1:protocoloRecebimento>
            <ns1:dataOperacao>XXXXXXX</ns1:dataOperacao>
            <ns1:recibo/>
        </ns2:entregarManifestacaoProcessualResposta>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

They haven't implemented according to the contract expressed, and in this situation the success must be false because the tag <ns1:recibo> is empty.

So I need to make an XSLT to check is recibo is empty and change the sucesso node to false.

I've started with the example below, that I've found here in SO, but when I try to change the sucesso node it never changes.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="Envelope/Body/sucesso">
    <sucesso>false</sucesso>
  </xsl:template>

</xsl:stylesheet>

1 Answer 1

1

I need to make an XSLT to check is recibo is empty and change the sucesso node to false.

Try it this way:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns2="XX">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="ns2:sucesso[not(../ns2:recibo/text())]">
    <xsl:copy>false</xsl:copy>
</xsl:template>

</xsl:stylesheet>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.