我定期从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>
答案 0 :(得分:2)
这有助于查看源XML,但我相信您可以使用:
XSLT 1.0
<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:strip-space elements="*"/>
<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>