dougou8552 2015-04-07 18:29
浏览 55

XSLT无法正确显示SOAP响应

I'm trying to display the result from the soap response into a table using XSLT but i'm getting a blank table. Here's the screenshot:

enter image description here

The reponse is not empty. I echoed it for you to see:

enter image description here

Here's my codes for the 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");
}

?>

This is my xslt file:

<?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>

This is the soap response:

<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>

Is my XSLT wrong? Please help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错
    • ¥15 单片机学习顺序问题!!
    • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上