Reza Akraminejad
Reza Akraminejad

Reputation: 1499

xslt transform error with web service soap return

I have a return soap xml from webservice :

<?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body><GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET">
    <GetCitiesByCountryResult>
      <NewDataSet>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Abadan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Omidieh</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Gach Saran Du Gunbadan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Masjed-Soleyman</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Ahwaz</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Bushehr Civ / Afb</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Bandar Lengeh</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Kermanshah</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Ghasre-Shirin</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Sanandaj</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Kashan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Esfahan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Shahre-Kord</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Rasht</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Arak</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Tehran-Mehrabad</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Ghazvin</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Semnan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Bandarabbass</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Kerman</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Bam</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Birjand</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Torbat-Heydarieh</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Mashhad</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Bojnourd</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Sabzevar</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Tabas</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Gorgan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Ramsar</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Abadeh</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Fasa</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Shiraz</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Khoy</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Orumieh</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Saghez</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Tabriz</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Zanjan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Yazd</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Zabol</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Chahbahar</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Zahedan</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Iranshahr</City>
  </Table>
  <Table>
    <Country>Iran, Islamic Republic of</Country>
    <City>Jask</City>
  </Table>
</NewDataSet>
</GetCitiesByCountryResult>
</GetCitiesByCountryResponse>
</soap:Body>
</soap:Envelope>

and I wrote xslt for that like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:p="http://www.webservicex.net">
  <xsl:template match="soap:Envelope/soap:Body/p:GetCitiesByCountryResponse/p:GetCitiesByCountryResult/p:NewDataSet">
    <xsl:for-each select="p:Table">
      <table>
        <Country>
          <xsl:value-of select="p:Country"/>
        </Country>
        <City>
          <xsl:value-of select="p:City"/>
        </City>
      </table>
    </xsl:for-each>
  </xsl:template>  
</xsl:stylesheet>

but transfrom return :

 <?xml version="1.0" encoding="utf-8"?>Iran, Islamic Republic ofAbadanIran, Islamic Republic ofOmidiehIran, Islamic Republic ofGach Saran Du GunbadanIran, Islamic Republic ofMasjed-SoleymanIran, Islamic Republic ofAhwazIran, Islamic Republic ofBushehr Civ / AfbIran, Islamic Republic ofBandar LengehIran, Islamic Republic ofKermanshahIran, Islamic Republic ofGhasre-ShirinIran, Islamic Republic ofSanandajIran, Islamic Republic ofKashanIran, Islamic Republic ofEsfahanIran, Islamic Republic ofShahre-KordIran, Islamic Republic ofRashtIran, Islamic Republic ofArakIran, Islamic Republic ofTehran-MehrabadIran, Islamic Republic ofGhazvinIran, Islamic Republic ofSemnanIran, Islamic Republic ofBandarabbassIran, Islamic Republic ofKermanIran, Islamic Republic ofBamIran, Islamic Republic ofBirjandIran, Islamic Republic ofTorbat-HeydariehIran, Islamic Republic ofMashhadIran, Islamic Republic ofBojnourdIran, Islamic Republic ofSabzevarIran, Islamic Republic ofTabasIran, Islamic Republic ofGorganIran, Islamic Republic ofRamsarIran, Islamic Republic ofAbadehIran, Islamic Republic ofFasaIran, Islamic Republic ofShirazIran, Islamic Republic ofKhoyIran, Islamic Republic ofOrumiehIran, Islamic Republic ofSaghezIran, Islamic Republic ofTabrizIran, Islamic Republic ofZanjanIran, Islamic Republic ofYazdIran, Islamic Republic ofZabolIran, Islamic Republic ofChahbaharIran, Islamic Republic ofZahedanIran, Islamic Republic ofIranshahrIran, Islamic Republic ofJask

should I use any other tag in converting in c#? is problem that I have xml values in it? whats the problem with my code?

Upvotes: 0

Views: 142

Answers (1)

Tim C
Tim C

Reputation: 70648

Your problem is with namespaces. You've correctly tried to reference the namespace in your XSLT, but you are not using the correct URI

In the XML, the namespace URI is declared like this..

xmlns="http://www.webserviceX.NET"

But in your XSLT, you declare it as this...

xmlns:p="http://www.webservicex.net"

XSLT is case-sensitive, so the two namespaces are considered to be different. This means your current template doesn't match anything, and as a result XSLT's built-in templates kick-in, which ultimately just outputs the text.

You just need to change the XSLT to be the same as the XML

<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
     xmlns:p="http://www.webserviceX.NET" 
     exclude-result-prefixes="soap p">

Upvotes: 1

Related Questions