Я пытаюсь сгенерировать xml из отклика xml с помощью таблицы стилей. Но не способен генерировать желаемый результат. Кажется, проблема связана с атрибутом xsi: type. Может ли кто-нибудь предложить возможные изменения в таблице стилей.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: величинаOnHand элемента ответа origina.
Ниже приведен 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"
\t \t \t \t xmlns:listAcct="urn:accounting_2015_1.lists.webservices.netsuite.com"
\t \t \t \t xmlns:platformCommon="urn:common_2015_1.platform.webservices.netsuite.com" xmlns:soapenv ="http://schemas.xmlsoap.org/soap/envelope/"
\t \t \t \t 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>
\t \t <updateList>
\t \t \t <xsl:for-each select="soapenv:Body/searchResponse/platformCore:searchResult/platformCore:searchRowList/platformCore:searchRow">
\t \t \t \t \t <updateItem>
\t \t \t \t \t <itemCode> \t \t \t \t \t
\t \t \t \t \t \t <xsl:value-of select="listAcct:basic/platformCommon:itemId/platformCore:searchValue"/>
\t \t \t \t \t </itemCode> \t \t \t \t
\t \t \t \t \t <quantityOnHand> \t \t \t \t \t
\t \t \t \t \t \t <xsl:value-of select="listAcct:basic/platformCommon:itemId/platformCore:searchValue"/>
\t \t \t \t \t </quantityOnHand>
\t \t \t \t \t </updateItem>
\t \t \t </xsl:for-each>
\t \t </updateList>
\t \t </soapenv:Body>
</xsl:template>
</xsl:stylesheet>
Это потому, что атрибут 'type' привязан к пространству имен' xsi'. Исходный XML-код недопустим. Он должен объявить пространство имен 'xsi'. –
Да, правильно..и сделал то же самое, что и я, – AriSan