我正在尝试使用样式表从响应xml生成xml。但是无法产生预期的结果。似乎问题在于xsi:type属性。任何人都可以建议样式表中的可能更改。
源XML
<soapenv:Body>
<searchResponse>
<platformCore:searchResult xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com">
<platformCore:status isSuccess="true"/>
<platformCore:totalRecords>17403</platformCore:totalRecords>
<platformCore:pageSize>1000</platformCore:pageSize>
<platformCore:totalPages>18</platformCore:totalPages>
<platformCore:pageIndex>1</platformCore:pageIndex>
<platformCore:searchId>WEBSERVICES_3479023_SB2_050620156958981381039449122_c4911d7b</platformCore:searchId>
<platformCore:searchRowList>
<platformCore:searchRow xsi:type="listAcct:ItemSearchRow" xmlns:listAcct="urn:accounting_2015_1.lists.webservices.netsuite.com">
<listAcct:basic xmlns:platformCommon="urn:common_2015_1.platform.webservices.netsuite.com">
<platformCommon:internalId>
<platformCore:searchValue internalId="2298"/>
</platformCommon:internalId>
<platformCommon:itemId>
<platformCore:searchValue>00411335</platformCore:searchValue>
</platformCommon:itemId>
<platformCommon:quantityAvailable>
<platformCore:searchValue>3721.0</platformCore:searchValue>
</platformCommon:quantityAvailable>
<platformCommon:quantityOnHand>
<platformCore:searchValue>3721.0</platformCore:searchValue>
</platformCommon:quantityOnHand>
</listAcct:basic>
</platformCore:searchRow>
<platformCore:searchRow xsi:type="listAcct:ItemSearchRow" xmlns:listAcct="urn:accounting_2015_1.lists.webservices.netsuite.com">
<listAcct:basic xmlns:platformCommon="urn:common_2015_1.platform.webservices.netsuite.com">
<platformCommon:internalId>
<platformCore:searchValue internalId="20284"/>
</platformCommon:internalId>
<platformCommon:itemId>
<platformCore:searchValue>0117022</platformCore:searchValue>
</platformCommon:itemId>
<platformCommon:quantityAvailable>
<platformCore:searchValue>545.0</platformCore:searchValue>
</platformCommon:quantityAvailable>
<platformCommon:quantityOnHand>
<platformCore:searchValue>551.0</platformCore:searchValue>
</platformCommon:quantityOnHand>
</listAcct:basic>
</platformCore:searchRow>
................. .................
期望的结果
<soapenv:Body>
<updateList>
<updateItem>
<itemCode></itemCode>
<quantityOnHand></quantityOnHand>
</updateItem>
<updateItem>
<itemCode></itemCode>
<quantityOnHand></quantityOnHand>
</updateItem>
<updateItem>
<itemCode></itemCode>
<quantityOnHand></quantityOnHand>
</updateItem>
................
........
</updateList>
itemCode和quantityOnHand元素将保存platformCommon的值:itemId和platformCommon:quantityOnHand原始响应的元素。
以下是我正在使用的XSL文件。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:platformCore="urn:core_2015_1.platform.webservices.netsuite.com"
xmlns:listAcct="urn:accounting_2015_1.lists.webservices.netsuite.com"
xmlns:platformCommon="urn:common_2015_1.platform.webservices.netsuite.com" xmlns:soapenv ="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<soapenv:Body>
<updateList>
<xsl:for-each select="soapenv:Body/searchResponse/platformCore:searchResult/platformCore:searchRowList/platformCore:searchRow">
<updateItem>
<itemCode>
<xsl:value-of select="listAcct:basic/platformCommon:itemId/platformCore:searchValue"/>
</itemCode>
<quantityOnHand>
<xsl:value-of select="listAcct:basic/platformCommon:itemId/platformCore:searchValue"/>
</quantityOnHand>
</updateItem>
</xsl:for-each>
</updateList>
</soapenv:Body>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
您无法对样式表做任何事情,使其接受格式错误的XML。 XML源包含
<platformCore:searchRow xsi:type="listAcct:ItemSearchRow"
xmlns:listAcct="urn:accounting_2015_1.lists.webservices.netsuite.com">
并且未声明xsi前缀。您需要修复XML。