-1

I have this basic SOAP response:

<?xml version="1.0" encoding="WINDOWS-1252" standalone="yes"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body xmlns="http://www.xxx.com/dotnet/types/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <a>
            <b>
                   <c>
                    c-value
                   </c>
                       b-value
            </b>
                a-value
        </a>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

and I want to output just the value of the c node: c-value.

I don't understand why this xsl is NOT working:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
>
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
 <xsl:value-of select="//c"/>
</xsl:template>
</xsl:stylesheet>

It seems that the problem is in the name space at <SOAP-ENV:Body xmlns="http://www.xxx.com/dotnet/types/" If I remove it, it works.

I guess I should change the xpath in select="//c" or add somewhere in the xls the needed namespace, but I can't get it right!

pnuts
  • 58,317
  • 11
  • 87
  • 139
Glasnhost
  • 1,023
  • 14
  • 34
  • 1
    possible duplicate of [How to 'select' from XML with namespaces with XSLT?](http://stackoverflow.com/questions/284094/how-to-select-from-xml-with-namespaces-with-xslt) – John Saunders Apr 06 '13 at 16:40
  • yes indeed...after hours of searching and trials, that links came out while writing the question, that's why I've included it in my answer...It's the same case but applied to SOAP, it's easy to overlook it. But I agree, it's a duplicate – Glasnhost Apr 07 '13 at 09:34

1 Answers1

1

ok, this link was helpful: How to 'select' from XML with namespaces?

I added the namespace like this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xxx="http://www.xxx.com/dotnet/types/"
>
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
 <xsl:value-of select="//xxx:c"/>
</xsl:template>
</xsl:stylesheet>

First the xmlns:xxx is added to the xlst and then the XPath becomes //xxx:c.

Writing questions in SO, solves problems...

Community
  • 1
  • 1
Glasnhost
  • 1,023
  • 14
  • 34