使用XSLT 1.0进行SOAP消息转换

时间:2015-07-25 07:11:38

标签: xml xslt soap

我正在开发一个应用程序,我需要发送一个SOAP请求来调用方法“authenticateCustomer”,其中包含一些参数,如“customerID”,“password”等。根据参数说“客户ID”,应用程序必须发送SOAP响应。我需要应用XSLT来准备应用程序发回的SOAP响应。但我无法从服务器生成适当的响应。以下是代码:

SOAP请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eps="http://www.eps.in.com">
<soapenv:Header/>
<soapenv:Body>
          <eps:authenticateCustomer>
             <eps:customerDetail>
                <eps:customerID>2</eps:customerID>
                <eps:password>abc</eps:password>
             </eps:customerDetail>
          </eps:authenticateCustomer>
    </soapenv:Body>
    </soapenv:Envelope>

预计回复: 当说customerID等于2时:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eps="http://www.eps.in.com">
   <soapenv:Header/>
   <soapenv:Body>
      <eps:authenticateCustomer>
         <eps:customerDetail>
            <eps:customerID>VALUE OF CUSTOMER ID</eps:customerID>
            <eps:password>VALUE OF PASSWORD</eps:password>
            <!--Optional:-->
            <eps:saltId>sss</eps:saltId>
            <!--Optional:-->
            <eps:systemID>SYSTEM1</eps:systemID>
            <eps:sourceSystem>FDWEB</eps:sourceSystem>
            <!--Optional:-->
            <eps:status>ACTIVE</eps:status>
         </eps:customerDetail>
      </eps:authenticateCustomer>
   </soapenv:Body>
</soapenv:Envelope>

当customerID不是2时:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eps="http://www.eps.in.com"><soapenv:Header/><soapenv:Body <eps:authenticateCustomer>
         <eps:customerDetail>
            <eps:customerID>VALUE OF CUSTOMER ID</eps:customerID>
            <eps:password>VALUE OF PASSWORD</eps:password>
            <!--Optional:-->
            <eps:saltId>sss</eps:saltId>
            <!--Optional:-->
            <eps:systemID>SYSTEM1</eps:systemID>
            <eps:sourceSystem>FDWEB</eps:sourceSystem>
            <!--Optional:-->
            <eps:status>ACTIVE</eps:status>
            <!--Optional:-->
            <eps:saltId>dhdkhf</eps:saltId>
            <!--Optional:-->
            <eps:systemID>dfhdgf</eps:systemID>
            <eps:sourceSystem>FDWEB</eps:sourceSystem>
            <!--Optional:-->
            <eps:status>ACTIVE</eps:status>
            <!--Optional:-->
            <eps:facebookUID>FB001</eps:facebookUID>
            <!--Optional:-->
            <eps:facebookURL>helloo</eps:facebookURL>
            <!--Optional:-->
            <eps:googleUID>GG190</eps:googleUID>
            <!--Optional:-->
            <eps:googleURL>google</eps:googleURL>
            <eps:domainName>HND</eps:domainName>
         </eps:customerDetail>
      </eps:authenticateCustomer>
   </soapenv:Body>
</soapenv:Envelope>

=============================================== =======================

我正在尝试应用以下XSLT来准备动态响应,但响应没有准备好:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:eps="http://www.eps.out.com" >
    <xsl:output method="xml" />
    <xsl:template match="/">
        <xsl:variable name="customerID" select="//customerID"/>
        <xsl:variable name="password" select="//password"/>

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eps="http://www.eps.out.com">
            <soapenv:Header />
            <soapenv:Body>
                <eps:customerID><xsl:value-of select="$customerID" /></eps:customerID>
                <xsl:message>Hello World!</xsl:message>
                <xsl:choose>
                    <xsl:when test="$customerID = 2">
                    <eps:authenticateCustomerResponse>
                            <eps:customerData>
                                <eps:authCode>AC<xsl:value-of select="$customerID" /></eps:authCode>
                                <eps:customerID><xsl:value-of select="$customerID" /></eps:customerID>
                                <eps:saltId>SA<xsl:value-of select="$customerID" /></eps:saltId>
                                <eps:sourceSystem>SS<xsl:value-of select="$customerID" /></eps:sourceSystem>
                                <eps:mdmID>?</eps:mdmID>
                                <eps:existingSystem>?</eps:existingSystem>
                                <eps:creationDate>?</eps:creationDate>
                                <eps:lastUpdateDate>?</eps:lastUpdateDate>
                                <eps:createdBy>?</eps:createdBy>
                                <eps:updatedBy>?</eps:updatedBy>
                                <eps:status>?</eps:status>
                            </eps:customerData>
                            <eps:error>
                                <eps:errorCode>?</eps:errorCode>
                                <eps:errorDetails>?</eps:errorDetails>
                            </eps:error>
                        </eps:authenticateCustomerResponse>
                    </xsl:when>
                    <xsl:otherwise>
                        <eps:authenticateCustomerResponse>
                            <eps:customerData>
                                <eps:authCode>AC<xsl:value-of select="$customerID" /></eps:authCode>
                                <eps:customerID><xsl:value-of select="$customerID" /></eps:customerID>
                                <eps:saltId>SA<xsl:value-of select="$customerID" /></eps:saltId>
                                <eps:sourceSystem>SS<xsl:value-of select="$customerID" /></eps:sourceSystem>
                                <eps:mdmID>?</eps:mdmID>
                                <eps:existingSystem>?</eps:existingSystem>
                                <eps:creationDate>?</eps:creationDate>
                                <eps:lastUpdateDate>?</eps:lastUpdateDate>
                                <eps:createdBy>?</eps:createdBy>
                                <eps:updatedBy>?</eps:updatedBy>
                                <eps:status>?</eps:status>
                                <eps:systemID>?</eps:systemID>
                                <eps:password>?</eps:password>
                                <eps:facebookUID>?</eps:facebookUID>
                                <eps:facebookURL>?</eps:facebookURL>
                                <eps:facebookUpdateFlag>?</eps:facebookUpdateFlag>
                                <eps:facebookUpdateDate>?</eps:facebookUpdateDate>
                                <eps:googleUID>?</eps:googleUID>
                                <eps:googleURL>?</eps:googleURL>
                                <eps:googleUpdateFlag>?</eps:googleUpdateFlag>
                                <eps:googleUpdateDate>?</eps:googleUpdateDate>
                                <eps:domainName>?</eps:domainName>
                            </eps:customerData>
                            <eps:error>
                                <eps:errorCode>?</eps:errorCode>
                                <eps:errorDetails>?</eps:errorDetails>
                            </eps:error>
                        </eps:authenticateCustomerResponse>
                    </xsl:otherwise>
                </xsl:choose>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>

我在哪里做错了?

2 个答案:

答案 0 :(得分:0)

根据您用于生成请求的语言,您可以使用本机SoapClient来正确包装所有内容。 例如,在PHP中,您可以使用PackageGenerator创建一个PHP包,它可以简化您发送请求的方式,而无需更改任何XML请求

答案 1 :(得分:0)

这是你犯的几个错误

  1. 示例中的命名空间为“http://www.eps.in.com”,而在XSLT中,您定义为“http://www.eps.out.com
  2. 查询时无法忽略命名空间,请使用以下命令在变量中存储值:<xsl:variable name="customerID" select="//eps:customerID" />
  3. XSLT看起来像SOAP响应,其中样本看起来像SOAP请求