我定期从 Access 导出数据。到目前为止,我曾经将其导出并手动编辑一些标签以根据客户需求进行调整。最近我发现可以使用 XSL 作为转换模式。
当谈到 XSL 时,我仍然是初学者,但设法创建了这样的东西:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="dataroot/Kwerenda_x0020_Nota_x0020_Kredytowa">
<xsl:element name="Faktury_od_nas">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
通常它工作正常,但是:
1. 通常当我导出数据时,它会给我一个新行中的每个标签,现在它只被我更改的标签划分。
2.我不知道如何重命名dataroot。我试图复制/粘贴相同的代码,但每次 Faktury_od_nas 出现时我都会得到 dataroot ......
转换后的样本数据:
<dataroot generated="2016-01-12T13:54:11" xmlns:od="urn:schemas-microsoft-com:officedata"><Faktury_od_nas><No>1</No><InvoiceDate>20150715</InvoiceDate><InvoiceNumber>12345</InvoiceNumber><CustVATNumber>LT100004645417</CustVATNumber><E100customerKey>65-92</E100customerKey><CustomerName>Client_name</CustomerName><InvoiceCountry>BE</InvoiceCountry><VATpersent>21</VATpersent><VATBasis>106,36</VATBasis><VATamount>22,34</VATamount><Currency>EUR</Currency><VAT_x0020_recovery_x0020_fee_x0020_rate_x0020__x0028__x0025__x0029_>7.5</VAT_x0020_recovery_x0020_fee_x0020_rate_x0020__x0028__x0025__x0029_><Service_x0020_Type>Express</Service_x0020_Type><InvoiceScanFileName>scan_name</InvoiceScanFileName>
</Faktury_od_nas></dararoot>
所需的样本数据:
<Faktura>
<Faktury_od_nas>
<No>1</No>
<InvoiceDate>20150715</InvoiceDate>
<InvoiceNumber>12345</InvoiceNumber>
<CustVATNumber>LT100004645417</CustVATNumber>
<E100customerKey>65-92</E100customerKey>
<CustomerName>Client_name</CustomerName>
<InvoiceCountry>BE</InvoiceCountry>
<VATpersent>21</VATpersent>
<VATBasis>106,36</VATBasis>
<VATamount>22,34</VATamount>
<Currency>EUR</Currency>
<VAT_x0020_recovery_x0020_fee_x0020_rate_x0020__x0028__x0025__x0029_>7.5</VAT_x0020_recovery_x0020_fee_x0020_rate_x0020__x0028__x0025__x0029_>
<Service_x0020_Type>Express</Service_x0020_Type>
<InvoiceScanFileName>scan_name</InvoiceScanFileName>
</Faktury_od_nas>
</Faktura>
我很感激任何帮助。
编辑:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="dataroot">
<Faktura>
<xsl:apply-templates />
</Faktura>
</xsl:template>
<xsl:template match="Kwerenda_x0020_Nota_x0020_Kredytowa">
<Faktury_od_nas>
<xsl:apply-templates />
</Faktury_od_nas>
</xsl:template>
</xsl:stylesheet>