XSL用於對XML進行反規範化以導入到平面數據庫表中。如何獲取當前元素屬性
對於每個發票invoiceid列都必須包含此發票ID。
但是由於未知原因,
<xsl:value-of select="../../../../../../Invoice/@invoiceId"/>
回報總是第一張發票編號1605002的arvenumber元素。所以所有的行都有相同的ID。 如何解決?
XML:
<?xml version="1.0" encoding="windows-1257"?>
<Envelope>
<Body>
<BuyInvoicesResponse>
<E_Invoice>
<Invoice invoiceId='1605002'>
<InvoiceItem>
<InvoiceItemGroup>
<ItemEntry>
<SellerProductId>YEYLD</SellerProductId>
<Description>Üldelekter</Description>
<EAN>23225325</EAN>
<ItemDetailInfo>
<ItemUnit>m2</ItemUnit>
<ItemAmount>1.96</ItemAmount>
<ItemPrice>1</ItemPrice>
</ItemDetailInfo>
<ItemSum>1.96</ItemSum>
<VAT>
<SumBeforeVAT>1.96</SumBeforeVAT>
<VATRate>0.00</VATRate>
<VATSum>0.00</VATSum>
</VAT>
<ItemTotal>1.96</ItemTotal>
</ItemEntry>
<ItemEntry>
<SellerProductId>YKV</SellerProductId>
<Description>Vesi ja kanalisatsioon</Description>
<EAN></EAN>
<ItemDetailInfo>
<ItemUnit>m3</ItemUnit>
<ItemAmount>4.10</ItemAmount>
<ItemPrice>2.07600</ItemPrice>
</ItemDetailInfo>
<ItemSum>8.51</ItemSum>
<VAT>
<SumBeforeVAT>8.51</SumBeforeVAT>
<VATRate>0.00</VATRate>
<VATSum>0.00</VATSum>
</VAT>
<ItemTotal>8.51</ItemTotal>
</ItemEntry>
<ItemEntry>
<SellerProductId>YPRYGI</SellerProductId>
<Description>Prügivedu</Description>
<EAN></EAN>
<ItemDetailInfo>
<ItemUnit>m2</ItemUnit>
<ItemAmount>1.84</ItemAmount>
<ItemPrice>1</ItemPrice>
</ItemDetailInfo>
<ItemSum>1.84</ItemSum>
<VAT>
<SumBeforeVAT>1.84</SumBeforeVAT>
<VATRate>0.00</VATRate>
<VATSum>0.00</VATSum>
</VAT>
<ItemTotal>1.84</ItemTotal>
</ItemEntry>
<ItemEntry>
<SellerProductId>YSV</SellerProductId>
<Description>Vee soojendamine</Description>
<EAN></EAN>
<ItemDetailInfo>
<ItemUnit>m3</ItemUnit>
<ItemAmount>1.50</ItemAmount>
<ItemPrice>2.10600</ItemPrice>
</ItemDetailInfo>
<ItemSum>3.16</ItemSum>
<VAT>
<SumBeforeVAT>3.16</SumBeforeVAT>
<VATRate>0.00</VATRate>
<VATSum>0.00</VATSum>
</VAT>
<ItemTotal>3.16</ItemTotal>
</ItemEntry>
</InvoiceItemGroup>
</InvoiceItem>
</Invoice>
<Invoice invoiceId='1605006'>
<InvoiceItem>
<InvoiceItemGroup>
<ItemEntry>
<SellerProductId>YEYLD</SellerProductId>
<Description>Üldelekter</Description>
<EAN>23225325</EAN>
<ItemDetailInfo>
<ItemUnit>m2</ItemUnit>
<ItemAmount>2.50</ItemAmount>
<ItemPrice>1</ItemPrice>
</ItemDetailInfo>
<ItemSum>2.50</ItemSum>
<VAT>
<SumBeforeVAT>2.50</SumBeforeVAT>
<VATRate>0.00</VATRate>
<VATSum>0.00</VATSum>
</VAT>
<ItemTotal>2.50</ItemTotal>
</ItemEntry>
</InvoiceItemGroup>
</InvoiceItem>
</Invoice>
</E_Invoice>
</BuyInvoicesResponse>
</Body>
</Envelope>
XSL:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes"/>
<xsl:template match="/">
<xsl:element name="VFPData">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="/Envelope/Body/BuyInvoicesResponse/E_Invoice/Invoice/InvoiceItem/InvoiceItemGroup/ItemEntry/Accounting/*">
<xsl:element name="Document-BuyInvoice">
<xsl:element name="arvenumber">
<xsl:value-of select="../../../../../../Invoice/@invoiceId"/>
</xsl:element>
<xsl:element name="nimetus">
<xsl:value-of select="../../Description"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- to ommit nodes data -->
<xsl:template match="text()">
</xsl:template>
<!-- to work over every node -->
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
MSXML分析器用於轉換
我在您的xml中看不到「會計」 – SomeDude