2016-09-26 155 views
0

我试图改变如下SOAP响应:如何XSLT转换SOAP响应

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<soapenv:Body> 
    <GetSellerListResponse xmlns="urn:ebay:apis:eBLBaseComponents"> 
    <Timestamp>2016-09-26T08:56:24.441Z</Timestamp> 
    <Ack>Success</Ack> 
    <Version>979</Version> 
    <Build>E979_CORE_API_18061413_R1</Build> 
    <PaginationResult> 
    <TotalNumberOfEntries>3</TotalNumberOfEntries> 
    </PaginationResult> 
    <ItemArray> 
    <Item> 
    <ItemID>110183939099</ItemID> 
    <ListingDetails> 
     <StartTime>2016-09-21T15:24:07.000Z</StartTime> 
     <EndTime>2016-09-28T15:24:07.000Z</EndTime> 
    </ListingDetails> 
    </Item> 
    <Item> 
    <ItemID>110183939198</ItemID> 
    <ListingDetails> 
     <StartTime>2016-09-21T15:29:50.000Z</StartTime> 
     <EndTime>2016-09-28T15:29:50.000Z</EndTime> 
    </ListingDetails> 
    </Item> 
    </ItemArray> 
    <ReturnedItemCountActual>3</ReturnedItemCountActual> 
    </GetSellerListResponse> 
</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"> 
<xsl:template match="//ItemArray"><xsl:text>&#xa;</xsl:text> 
<entries entity="Product" action="import"><xsl:text>&#xa;</xsl:text> 
<xsl:for-each select="Item"> 
<entry externalReference="{ItemID}" thirdPartyReference="{ItemID}"/><xsl:text>&#xa;</xsl:text> 
</xsl:for-each> 
</entries> 
</xsl:template> 
</xsl:stylesheet> 

这就是我想要的变换的结果为:

<?xml version="1.0" encoding="UTF-8"?> 
<entries entity="Product" action="import"> 
<entry externalReference="110183876099" thirdPartyReference="110183876099"/> 
<entry externalReference="110183876188" thirdPartyReference="110183876188"/> 
</entries> 

但是目前它的输出是这样的:

<?xml version="1.0" encoding="UTF-8"?> 


    2016-09-26T08:56:24.441Z 
    Success 
    979 
    E979_CORE_API_18061413_R1 

    2 



    110183876099 

     2016-09-21T15:24:07.000Z 
     2016-09-28T15:24:07.000Z 



    110183876188 

     2016-09-21T15:29:50.000Z 
     2016-09-28T15:29:50.000Z 



    2 

我在做错在这里在我的XSLT格式化不能得到所需的输出?

回答

1

问题: Missmatch在表达式中的命名空间的

见主题:Use of XSLT namespaces

解决方案:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bl="urn:ebay:apis:eBLBaseComponents" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    exclude-result-prefixes="xsl bl soapenv"> 

    <xsl:template match="/"> 
     <xsl:apply-templates select="soapenv:Envelope/soapenv:Body/bl:GetSellerListResponse/bl:ItemArray"/> 
    </xsl:template> 

    <xsl:template match="bl:ItemArray"><xsl:text>&#xa;</xsl:text> 
     <entries entity="Product" action="import"><xsl:text>&#xa;</xsl:text> 
      <xsl:for-each select="bl:Item"> 
       <entry externalReference="{bl:ItemID}" thirdPartyReference="{bl:ItemID}"/><xsl:text>&#xa;</xsl:text> 
      </xsl:for-each> 
     </entries> 
    </xsl:template> 
</xsl:stylesheet>