我正在尝试转换以下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>
</xsl:text>
<entries entity="Product" action="import"><xsl:text>
</xsl:text>
<xsl:for-each select="Item">
<entry externalReference="{ItemID}" thirdPartyReference="{ItemID}"/><xsl:text>
</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格式化中,我做错了什么不能获得所需的输出?
答案 0 :(得分:1)
问题:表达式中名称空间不匹配
请参阅帖子: 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>
</xsl:text>
<entries entity="Product" action="import"><xsl:text>
</xsl:text>
<xsl:for-each select="bl:Item">
<entry externalReference="{bl:ItemID}" thirdPartyReference="{bl:ItemID}"/><xsl:text>
</xsl:text>
</xsl:for-each>
</entries>
</xsl:template>
</xsl:stylesheet>