Reputation: 441
So I'm trying to convert (Extract) all the elements within the body of a SOAP document into XML using XSLT. Here's my SOAP document (complete)
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="dealercode.xsl"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader xmlns="http://www.somedomain.com/">
<LogonID></LogonID>
<Password></Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<getDealerCodeById xmlns="http://www.somedomain.com/">
<BrokerCode>{ssQuoterBrokerCode(app_id)}</BrokerCode>
<IDNumber>{dealerCode}</IDNumber>
</getDealerCodeById>
</soap:Body>
</soap:Envelope>
And Here's my XSLT sheet.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<?xml-stylesheet type="text/xsl" href="dealercode2soap.xsl"?>
<xsl:template match="/*">
<xsl:value-of select="soap:Body/s:getDealerCodeById"
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
xmlns:s="http://somedomainname/" />
</xsl:stylesheet>
But the output is not what I want. It is still parsing the whole SOAP document instead of just giving me the contents within the "soap:Body" elements and it I am also getting a warning of "unresolved namespace prefix soap"
Where am I going wrong?
EDIT: I managed to get it to work making use of a different block of code. See below
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns ="http://www.somedomainename.com">
<xsl:template match="/">
<xsl:apply-templates select="soap:Envelope/soap:Body/*"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
It now outputs in my browser the contents of the body section. The other most important thing I realized was that formatting was done on the server side but since I did not have access to the server at the time I had no idea whether my code was working or not. This is the desired output I was looking for (which was apparently working the whole time.
<?xml version="1.0" encoding="UTF-8"?>
<getDealerCodeById xmlns="http:///" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<BrokerCode>{ssQuoterBrokerCode(app_id)}</BrokerCode>
<IDNumber>{dealerCode}</IDNumber>
</getDealerCodeById>
Upvotes: 2
Views: 6514
Reputation: 163625
Modifying the code in your question means that we can't see what question Mads was answering, which make it very difficult to follow the thread. But the situation with your code as it is right now is that you bind the soap prefix to different namespaces in the source document and the stylesheet, which is not illegal but is certainly confusing and unlikely to be what you intended. The namespace for somedomain.com doesn't match either.
I would expect the effect of these errors to be that your stylesheet outputs nothing. I don't know what you mean by saying "it is parsing the whole document" - stylesheets always parse the whole input document. Do you mean it is outputting the whole of the input document? That certainly doesn't seem consistent with your code.
Upvotes: 0
Reputation: 66781
You are getting the warning about "Unresolved namespace prefix soap" because you have not declared the soap
namespace in your XSLT.
Also, your getDealerCodeById
element is bound to the http://somedomainname/
namespace-uri. You may not have noticed, because it does not use a namespace-prefix: xmlns="http://somedomainname/"
Be sure to declare both the soap
namespace and the http://somedomainname/
namespace in your XSLT and adjust your XPath to use whatever namespace-prefix you declare:
<xsl:template match="/*">
<xsl:value-of select="soap:Body/s:getDealerCodeById"
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
xmlns:s="http://somedomainname/" />
</xsl:template>
Upvotes: 2