简体   繁体   中英

Avoid escaping < and > on xsl transformation

I'm trying to filter, select and use some values of this main xml element.

Payload :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
    <text xmlns="http://ws.apache.org/commons/ns/payload">
        <xml>
            <resultCode>1</resultCode>
            <descErro>Ops, aconteceu algo errado aqui!  O numA [null] informado pela URA eh nulo e nao eh valido! Favor rever as configuracoes </descErro>
        </xml>
    </text>
</soapenv:Body>

My XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="2.0"
    xmlns:int="http://ws.apache.org/commons/ns/payload"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes"><![CDATA[
      <result>
         <xsl:if test="soapenv:Envelope/soapenv:Body/text/xml/resultCode = '0'">
            <quote>
               <value>
                  <xsl:value-of select="soapenv:Envelope/soapenv:Body/text/xml/resultCode"/>
               </value>
            </quote>
            <code>
               <xsl:value-of select="soapenv:Envelope/soapenv:Body/text/xml/cota"/>
            </code>
         </xsl:if>
         <xsl:if test="soapenv:Envelope/soapenv:Body/text/xml/resultCode != '0'">
            <code>
               <xsl:value-of select="soapenv:Envelope/soapenv:Body/text/xml/resultCode"/>
            </code>
            <message>
               <xsl:value-of select="soapenv:Envelope/soapenv:Body/text/xml/descErro"/>
            </message>
         </xsl:if>
       </result>]]></xsl:text>
    </xsl:template>
</xsl:transform>

What am I missing? Im not managing to reach the payload elements...

CDATA means "character data". It means "the stuff in here might look like markup, but it isn't.". So if you have a stylesheet containing CDATA, and inside the CDATA section is something that looks like an xsl:if instruction, then that's an optical illusion: it's not really an xsl:if instruction at all, it's just text to be copied into the result document.

So that explains why your code isn't working. How to fix it? Well that depends on knowing what you want to do, which you haven't told us. It's hard to reverse engineer your requirements from non-working code. Show us your expected output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM