我正在尝试使用XSLT将soap响应的结果显示到表中,但我得到一张空白表。 这是截图:
响应不是空的。我回答你的看法:
这是我的client.php代码:
<?php
if(isset($_POST['search_input']))
{
try
{
$input = $_POST['search_input'];
$wsdl = "http://localhost/WebService/UDDI/90210Store.wsdl";
//$options = array('cache_wsdl'=>WSDL_CACHE_NONE, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS);
//$client = new SoapClient($wsdl, $options);
$debugOption = array('trace'=>true, 'cache_wsdl'=>WSDL_CACHE_NONE, 'features'=>SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new SoapClient($wsdl, $debugOption);
$response = $client->viewDressPerPrice($input);
/*$res = var_dump($response);
echo $res;*/
$soaprequest = "<strong>REQUEST:</strong><br/>" . $client->__getLastRequest() . "<br/>";
$soapresponse = $client->__getLastResponse();
echo $soapresponse;
//$decode = html_entity_decode($soapresponse);
//echo $decode;
if(isset($response->DressPerPrice))
{
$XMLDocument = simplexml_load_string($soapresponse);
$XSLDocument = new DOMDocument();
$XSLDocument->load("WSEx1.xsl");
$XSLProcessor = new XSLTProcessor();//PHP5
$XSLProcessor->importStylesheet($XSLDocument);
echo $XSLProcessor->transformToXML($XMLDocument);
}
else
{
echo "This field is not found in database";
}
}
catch(Exception $e)
{
echo 'Exception: '.$e->getMessage();
}
catch(SOAPFault $exception)
{
echo 'SOAP Exception: '.$exception->getMessage();
}
}
else
{
header("Location: http://localhost/WebService/Client/Category.html");
}
?>
这是我的xslt文件:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*" />
<xsl:template match="/">
<html>
<head><title>Web Service</title>
<link rel="stylesheet" type="text/css" href="WSEx1.css"/>
</head>
<body>
<h3>Dresses Per Price</h3>
<table border="1">
<thead>
<tr style="background-color:PaleGreen;"><th>Name</th><th>Price</th><th>Image</th></tr>
</thead>
<tbody>
<xsl:for-each select="Result">
<xsl:apply-templates>
<xsl:sort select="Price" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:for-each>
</tbody>
</table>
<p><strong>Note:</strong>Data listed above may not reflect the current state at CSE.</p>
</body>
</html>
</xsl:template>
<xsl:template match="DressPerPrice">
<xsl:variable name="cssClass">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">coloured</xsl:when>
<xsl:otherwise>normal</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr class="{$cssClass}">
<xsl:apply-templates select="Name"/>
<xsl:apply-templates select="Price"/>
<xsl:apply-templates select="Image"/>
</tr>
</xsl:template>
<xsl:template match="DressPerPrice|Name|Price">
<td><xsl:value-of select="text()"/></td>
</xsl:template>
</xsl:stylesheet>
这是肥皂回应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.shehzad.edu/webservice">
<SOAP-ENV:Body>
<ns1:Result>
<ns1:DressPerPrice>
<ns1:Name>Dress 2</ns1:Name>
<ns1:Price>20</ns1:Price>
<ns1:Image>2.jpeg</ns1:Image>
</ns1:DressPerPrice>
<ns1:DressPerPrice>
<ns1:Name>Dress 9</ns1:Name>
<ns1:Price>20</ns1:Price>
<ns1:Image>3.jpeg</ns1:Image>
</ns1:DressPerPrice>
<ns1:DressPerPrice>
<ns1:Name>Dress 10</ns1:Name>
<ns1:Price>20</ns1:Price>
<ns1:Image>0905C58A0179_1.jpeg</ns1:Image>
</ns1:DressPerPrice>
<ns1:DressPerPrice>
<ns1:Name>Dress 11</ns1:Name>
<ns1:Price>20</ns1:Price>
<ns1:Image>0905C58A0179_1.jpeg</ns1:Image>
</ns1:DressPerPrice>
<ns1:DressPerPrice>
<ns1:Name>Dress 12</ns1:Name>
<ns1:Price>20</ns1:Price>
<ns1:Image>0905C58A0179_1.jpeg</ns1:Image>
</ns1:DressPerPrice>
</ns1:Result>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我的XSLT错了吗?请帮忙。