我有以下XML。
<?xml version="1.0" encoding="utf-8"?>
<ordersPack id="1398720518" ic="12345678" application="Web" version="2.0" note="user">
<orderPackItem id="2014042847">
<order>
<orderHeader>
<numberOrder>2014042847</numberOrder>
<partnerIdentity>
<billing>
<firstname>Ilona</firstname>
<surname>Kokerková</surname>
</billing>
</partnerIdentity>
</orderHeader>
<orderDetail>
<orderItem>
<name><![CDATA[Kokosový panenský olej 1000 ml]]></name>
<unitPriceWithTax>290.00</unitPriceWithTax>
</orderItem>
<orderItem>
<name><![CDATA[Dobírka ČP - Balík na poštu]]></name>
<quantity>1</quantity>
<percentVAT>21</percentVAT>
<unitPrice>86.78</unitPrice>
<unitPriceWithTax>105.00</unitPriceWithTax>
</orderItem>
</orderDetail>
<orderSummary>
</orderSummary>
</order>
</orderPackItem>
<orderPackItem id="2014042846">
<order>
<orderHeader>
<orderType>receivedOrder</orderType>
<partnerIdentity>
<billing>
<firstname>David</firstname>
<surname>Liala</surname>
</billing>
</partnerIdentity>
</orderHeader>
<orderDetail>
<orderItem>
<name><![CDATA[Mikula Bio Mladý ječmen prášek 250 g]]></name>
<unitPriceWithTax>469.00</unitPriceWithTax>
</orderItem>
<orderItem>
<name><![CDATA[osobní odběr Brno, Orlí 16, AWA centrum]]></name>
<unitPriceWithTax>0.00</unitPriceWithTax>
</orderItem>
</orderDetail>
<orderSummary>
</orderSummary>
</order>
</orderPackItem>
</ordersPack>
如果<dat:dataPackItem>
包含“Hotově,osobníodběr”,我需要使用<inv:text>Hotově, osobní odběr</inv:text>
排除所有项目。
欲望输出是:
<?xml version="1.0" encoding="windows-1250"?>
<dat:dataPack id="fa002" ico="12345678" application="StwTest" version="2.0" note="FA" ">
<dat:dataPackItem id="2014042847" version="2.0">
<inv:invoice version="2.0">
<inv:invoiceHeader>
<inv:invoiceType>issuedInvoice</inv:invoiceType>
</inv:accounting>
<inv:classificationVAT>
<typ:ids>UD</typ:ids>
</inv:classificationVAT>
<inv:partnerIdentity>
<typ:address>
<typ:company>firma</typ:company>
<typ:division>Obchodní oddělení</typ:division>
<typ:name>IlonaKokerková</typ:name>
</typ:address>
</inv:partnerIdentity>
<inv:paymentType>
<typ:paymentType>delivery</typ:paymentType>
</inv:paymentType>
<inv:account>
<typ:ids>KB</typ:ids>
</inv:account>
<inv:intNote>Faktura s textovou a skladovou položkou</inv:intNote>
</inv:invoiceHeader>
<inv:invoiceDetail>
<inv:invoiceItem>
<inv:text>Kokosový panenský olej 1000 ml</inv:text>
<inv:homeCurrency>
<typ:unitPrice>290.00</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids>awa1265</typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
<inv:invoiceItem>
<inv:text>Dobírka zboží</inv:text>
<inv:homeCurrency>
<typ:unitPrice>0.00</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids></typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
<inv:invoiceItem>
<inv:text>Dobírka ČP - Balík na poštu</inv:text>
<inv:homeCurrency>
<typ:unitPrice>105.00</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids></typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
</inv:invoiceDetail>
</inv:invoice>
</dat:dataPackItem>
</dat:dataPack>
如果<dat:dataPackItem>
包含“Hotově,osobníodběr”,我需要使用<inv:text>Hotově, osobní odběr</inv:text>
排除所有项目。
怎么做?
这是我的XSLT ....
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" indent="yes" encoding="windows-1250" />
<xsl:template match="/">
<dat:dataPack id="fa002" ico="12345678" application="StwTest" version = "2.0" note="Import FA">
<xsl:for-each select="ordersPack/orderPackItem">
<dat:dataPackItem id="{order/orderHeader/numberOrder}" version="2.0">
<!-- faktura bez adresy s textovou a skladovou polozkou-->
<inv:invoice version="2.0">
<inv:invoiceHeader>
<inv:symVar>
<xsl:value-of select="order/orderHeader/numberOrder"/>
</inv:symVar>
<inv:numberOrder>
<xsl:value-of select="order/orderHeader/numberOrder"/>
</inv:numberOrder>
<inv:dateOrder>
<xsl:value-of select="order/orderHeader/dateFrom"/>
</inv:dateOrder>
<inv:partnerIdentity>
<typ:address>
<typ:company>firma</typ:company>
<typ:division>Obchodní oddělení</typ:division>
<typ:name>
<xsl:value-of select="order/orderHeader/partnerIdentity/billing/firstname"/>
<xsl:value-of select="order/orderHeader/partnerIdentity/billing/surname"/>
</typ:name>
</typ:address>
</inv:partnerIdentity>
<inv:paymentType>
<typ:paymentType>
<xsl:choose><xsl:when test="order/orderDetail/orderItem/name='Dobírka zboží'">delivery</xsl:when>
<xsl:otherwise>draft</xsl:otherwise></xsl:choose>
</typ:paymentType>
</inv:paymentType>
<inv:account>
<typ:ids>KB</typ:ids>
</inv:account>
<inv:note>Načteno z XML</inv:note>
<inv:intNote>Faktura s textovou a skladovou položkou</inv:intNote>
</inv:invoiceHeader>
<inv:invoiceDetail>
<!--skladova polozka-->
<xsl:for-each select="order/orderDetail/orderItem">
<inv:invoiceItem>
<inv:text>
<xsl:value-of select="name"/>
</inv:text>
<inv:quantity>
<xsl:value-of select="quantity"/>
</inv:quantity>
<inv:payVAT>true</inv:payVAT>
<xsl:choose>
<xsl:when test="percentVAT = '15'">
<inv:rateVAT>low</inv:rateVAT>
</xsl:when>
<xsl:when test="percentVAT = '21'">
<inv:rateVAT>high</inv:rateVAT>
</xsl:when>
</xsl:choose>
<inv:homeCurrency>
<typ:unitPrice>
<xsl:value-of select="unitPriceWithTax"/>
</typ:unitPrice>
</inv:homeCurrency>
<inv:stockItem>
<typ:stockItem>
<typ:ids>
<xsl:value-of select="product_nr"/>
</typ:ids>
</typ:stockItem>
</inv:stockItem>
</inv:invoiceItem>
</xsl:for-each>
</inv:invoiceDetail>
</inv:invoice>
</dat:dataPackItem>
</xsl:for-each>
</dat:dataPack>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
您需要考虑输入,而不是输出。如果您要排除orderItem
包含“Hotově,osobníodběr”的所有name
元素,则需要在orderItem
for-each
添加谓词:
<!--skladova polozka-->
<xsl:for-each select="order/orderDetail/orderItem[not(contains(name, 'Hotově, osobní odběr'))]">
要使用此文本完全删除包含任何orderPackItem
的任何orderItem
,您需要顶级谓词:
<xsl:for-each select="ordersPack/orderPackItem[
not(order/orderDetail/orderItem[
contains(name, 'Hotově, osobní odběr')])]">