Reputation: 86
am trying to transform soap response to xml using xslt but am getting only empty output. Please any one help me.
MY Soap response is
<Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Body
xmlns="http://schemas.xmlsoap.org/soap/envelope">
<OTA_HotelAvailRS TransactionIdentifier="12345" EchoToken="12345" Target="Test" TimeStamp="2008-03-18T10:46:53.393" Version="6.001">
<HotelImages>
<ImagePath>http://reznextlive.blob.core.windows.net/custcode-106/63710.jpg</ImagePath>
<ImagePath>http://reznextlive.blob.core.windows.net/custcode-106/63711.jpg</ImagePath>
<ImagePath>http://reznextlive.blob.core.windows.net/custcode-106/63712.jpg</ImagePath>
</HotelImages>
</OTA_HotelAvailRS>
</Body>
</Envelope>
My XSLT IS
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<images>
<xsl:value-of select="Envelope/Body/OTA_HotelAvailRS/HotelImages/ImagePath"/>
</images>
</xsl:template>
</xsl:stylesheet>
My output is like
<?xml version="1.0" encoding="utf-8"?>
<images xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"/>
Upvotes: 0
Views: 5994
Reputation: 640
hope this helps,
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope"
exclude-result-prefixes="xsl xsi env xsd">
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<root>
<xsl:for-each select="Envelope/env:Body/env:OTA_HotelAvailRS/env:HotelImages/env:ImagePath">
<images>
<xsl:value-of select="current()"/>
</images>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
You have to specify the namespace to which the node belongs in source xml, within xslt to access that node in xslt
Upvotes: 2
Reputation: 169
Your stylesheet was close but at the <Body>
tag there is an xmlns
default namespace declaration that applies to that node and all of the children. It looks like you might have tried that because the soap
prefix was declared in your stylesheet. Unfortunately the soap namespace in your stylesheet was incorrect; there should be no trailing /
. Namespaces are compared lexically not semantically so the two are not equivalent.
Here is a sample:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope">
<xsl:output method="xml" omit-xml-declaration="no" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<images>
<xsl:for-each select="Envelope/soap:Body/soap:OTA_HotelAvailRS/soap:HotelImages/soap:ImagePath">
<xsl:value-of select="." />,
</xsl:for-each>
</images>
</xsl:template>
</xsl:stylesheet>
The output you would get in your stylesheet would be the first image only. I added a xsl:for-each
here as a sample.
Upvotes: 2