我正在使用SSIS中的XSLT将XML导入任务用于非规范化文件。以下是XML内容。
<?xml version="1.0" encoding="UTF-8"?>
<ReceiptConfirmation>
<File>
<FileNumber>11520</FileNumber>
<FileCreationDate>2014-02-11</FileCreationDate>
<FileCreationTime>20:50:23</FileCreationTime>
</File>
<Receipts>
<Receipt>
<InboundID>2136</InboundID>
<ReceiptID>R00706</ReceiptID>
<Vendor>DayMen</Vendor>
<ReceiptDate>2013-12-11</ReceiptDate>
<ReceiptTime>11:32:21</ReceiptTime>
<ReceiptType>RMA</ReceiptType>
<PartReceipts>
<PartReceipt>
<PartRef>JB00128-CEN</PartRef>
<QtyExpected>2</QtyExpected>
<QtyReceived>0</QtyReceived>
<StockStatus>Inspection</StockStatus>
</PartReceipt>
<PartReceipt>
<PartRef>JB01259-BWW</PartRef>
<QtyExpected>2</QtyExpected>
<QtyReceived>2</QtyReceived>
<StockStatus>Inspection</StockStatus>
</PartReceipt>
<PartReceipt>
<PartRef>JB01257-BWW</PartRef>
<QtyExpected>1</QtyExpected>
<QtyReceived>1</QtyReceived>
<StockStatus>Inspection</StockStatus>
</PartReceipt>
<PartReceipt>
<PartRef>JB01112-BWW</PartRef>
<QtyExpected>3</QtyExpected>
<QtyReceived>3</QtyReceived>
<StockStatus>Inspection</StockStatus>
</PartReceipt>
</PartReceipts>
</Receipt>
</Receipts>
</ReceiptConfirmation>
我使用的xslt是
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<File>
<xsl:for-each select="ReceiptConfirmation/Receipts">
<xsl:for-each select="ReceiptConfirmation/Receipts/Receipt/PartReceipt">
<ReceiptConfirmation>
<FileNumber><xsl:value-of select="ReceiptConfirmation/File/FileNumber"/>
</FileNumber>
<FileCreationDate><xsl:value-of select="ReceiptConfirmation/File/FileCreationDate"/>
</FileCreationDate>
<FileCreationTime><xsl:value-of select="ReceiptConfirmation/File/FileCreationTime"/>
</FileCreationTime>
<InboundID><xsl:value-of select="ReceiptConfirmation/Receipts/Receipt/InboundID"/>
</InboundID>
<ReceiptID><xsl:value-of select="ReceiptConfirmation/Receipts/Receipt/ReceiptID"/>
</ReceiptID>
<Vendor><xsl:value-of select="ReceiptConfirmation/Receipts/Receipt/Vendor"/>
</Vendor>
<ReceiptDate><xsl:value-of
select="ReceiptConfirmation/Receipts/Receipt/ReceiptDate"/></ReceiptDate>
<ReceiptTime><xsl:value-of
select="ReceiptConfirmation/Receipts/Receipt/ReceiptTime"/></ReceiptTime>
<ReceiptType><xsl:value-of
select="ReceiptConfirmation/Receipts/Receipt/ReceiptType"/></ReceiptType>
<PartRef><xsl:value-of
select="ReceiptConfirmation/Receipts/Receipt/PartReceipts/PartReceipt/PartRef"/>
</PartRef>
<QtyExpected><xsl:value-of
select="ReceiptConfirmation/Receipts/Receipt/PartReceipts/PartReceipt/QtyExpected"/>
</QtyExpected>
<QtyReceived><xsl:value-of select="ReceiptConfirmation/Receipts/Receipt/PartReceipts/PartReceipt/QtyExpected"/>
</QtyReceived>
<StockStatus><xsl:value-of
select="ReceiptConfirmation/Receipts/Receipt/PartReceipts/PartReceipt/QtyExpected"/>
</StockStatus>
</ReceiptConfirmation>
</xsl:for-each>
</xsl:for-each>
</File>
</xsl:template>
</xsl:stylesheet>
我需要一些帮助来设置两个节点之间的循环并使用xslt获得结果。
这就是我所期待的。
<?xml version="1.0" encoding="utf-8"?>
<ReceiptConfirmation>
<Receipt>
<FileNumber>11520</FileNumber>
<FileCreationDate>2014-02-11</FileCreationDate>
<FileCreationTime>20:50:23</FileCreationTime>
<InboundID>2136</InboundID>
<ReceiptID>R00706</ReceiptID>
<Vendor>DayMen</Vendor>
<ReceiptDate>2013-12-11</ReceiptDate>
<ReceiptTime>11:32:21</ReceiptTime>
<ReceiptType>RMA</ReceiptType>
<PartRef>JB00128-CEN</PartRef>
<QtyExpected>2</QtyExpected>
<QtyReceived>2</QtyReceived>
<StockStatus>Inspection</StockStatus>
</Receipt>
<Receipt>
<FileNumber>11520</FileNumber>
<FileCreationDate>2014-02-11</FileCreationDate>
<FileCreationTime>20:50:23</FileCreationTime>
<InboundID>2136</InboundID>
<ReceiptID>R00706</ReceiptID>
<Vendor>DayMen</Vendor>
<ReceiptDate>2013-12-11</ReceiptDate>
<ReceiptTime>11:32:21</ReceiptTime>
<ReceiptType>RMA</ReceiptType>
<PartRef>JB00129-CEN</PartRef>
<QtyExpected>2</QtyExpected>
<QtyReceived>2</QtyReceived>
<StockStatus>Inspection</StockStatus>
</Receipt>
<Receipt>
<FileNumber>11520</FileNumber>
<FileCreationDate>2014-02-11</FileCreationDate>
<FileCreationTime>20:50:23</FileCreationTime>
<InboundID>2136</InboundID>
<ReceiptID>R00706</ReceiptID>
<Vendor>DayMen</Vendor>
<ReceiptDate>2013-12-11</ReceiptDate>
<ReceiptTime>11:32:21</ReceiptTime>
<ReceiptType>RMA</ReceiptType>
<PartRef>JB00130-CEN</PartRef>
<QtyExpected>2</QtyExpected>
<QtyReceived>2</QtyReceived>
<StockStatus>inStock</StockStatus>
</Receipt>
</ReceiptConfirmation>
答案 0 :(得分:1)
我认为(或猜测)这会做你想做的事情:
<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="/">
<ReceiptConfirmation>
<xsl:for-each select="ReceiptConfirmation/Receipts/Receipt/PartReceipts/PartReceipt">
<Receipt>
<xsl:copy-of select="ancestor::ReceiptConfirmation/File/*"/>
<xsl:copy-of select="ancestor::Receipt/*[not(*)]"/>
<xsl:copy-of select="*"/>
</Receipt>
</xsl:for-each>
</ReceiptConfirmation>
</xsl:template>
</xsl:stylesheet>