有人可以协助创建密钥,以便使用xsl正确分组xml文件吗?使用收到的xml我需要能够将数据带入我的ERP系统,从而为每个新供应商以及每个目的地仓库创建新的采购订单。换句话说,从下面我需要为LIY0001创建的采购订单并转到A4(这必须包括与供应商和仓库相关的所有行)。类似地,需要为WOR0001转到A4而另一个为WOR0001转到A5创建新的采购订单(同样,所有与两个键相关的行都进入必要的采购订单分组)。对于下面的示例,应该创建3个单独的采购订单。
以下是xml的示例:
<rows>
<row>
<SUPPLIER>LIY0001</SUPPLIER>
<DESTWHS>A4</DESTWHS>
<RELEASE_DATE>2013-02-14</RELEASE_DATE>
<DUE_DATE>2013-05-13</DUE_DATE>
<ITEM>5021616</ITEM>
<QTY>528</QTY>
<LINE_ITEM_NO>1</LINE_ITEM_NO>
<CUST_PO_NO>LIY0001-2013-02-14</CUST_PO_NO>
<PURCHASEPRICE>5.25</PURCHASEPRICE>
</row>
<row>
<SUPPLIER>LIY0001</SUPPLIER>
<DESTWHS>A4</DESTWHS>
<RELEASE_DATE>2013-02-14</RELEASE_DATE>
<DUE_DATE>2013-05-13</DUE_DATE>
<ITEM>5021816</ITEM>
<QTY>222</QTY>
<LINE_ITEM_NO>2</LINE_ITEM_NO>
<CUST_PO_NO>LIY0001-2013-02-14</CUST_PO_NO>
<PURCHASEPRICE>5.90</PURCHASEPRICE>
</row>
<row>
<SUPPLIER>WOR0001</SUPPLIER>
<DESTWHS>A4</DESTWHS>
<RELEASE_DATE>2013-02-14</RELEASE_DATE>
<DUE_DATE>2013-05-13</DUE_DATE>
<ITEM>650616</ITEM>
<QTY>129</QTY>
<LINE_ITEM_NO>9</LINE_ITEM_NO>
<CUST_PO_NO>WOR0001-2013-02-14</CUST_PO_NO>
<PURCHASEPRICE>4.46</PURCHASEPRICE>
</row>
<row>
<row>
<SUPPLIER>WOR0001</SUPPLIER>
<DESTWHS>A5</DESTWHS>
<RELEASE_DATE>2013-02-14</RELEASE_DATE>
<DUE_DATE>2013-05-13</DUE_DATE>
<ITEM>650610</ITEM>
<QTY>129</QTY>
<LINE_ITEM_NO>1</LINE_ITEM_NO>
<CUST_PO_NO>WOR0001-2013-02-14</CUST_PO_NO>
<PURCHASEPRICE>3.5</PURCHASEPRICE>
</row>
<row>
</rows>
这是我创建的翻译文件:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="Windows-1252" omit-xml-declaration="yes" />
<xsl:template match="/">
<PostPurchaseOrders>
<Orders>
<OrderHeader>
<xsl:for-each select = "rows/row">
<CustomerPoNumber><xsl:value-of select="CUST_PO_NO"/></CustomerPoNumber>
<Supplier><xsl:value-of select="SUPPLIER"/></Supplier>
<OrderDate><xsl:value-of select="RELEASE_DATE"/></OrderDate>
<DueDate><xsl:value-of select="DUE_DATE"/></DueDate>
<Warehouse><xsl:value-of select="DESTWHS"/></Warehouse>
</xsl:for-each>
</OrderHeader>
<OrderDetails>
<xsl:for-each select = "rows/row">
<StockLine>
<PurchaseOrderLine><xsl:value-of select="LINE_ITEM_NO"/></PurchaseOrderLine>
<StockCode><xsl:value-of select="ITEM"/></StockCode>
<Warehouse><xsl:value-of select="DESTWHS"/></Warehouse>
<OrderQty><xsl:value-of select="QTY"/></OrderQty>
<Price><xsl:value-of select="PURCHASEPRICE"/></Price>
</StockLine>
</xsl:for-each>
</OrderDetails>
</Orders>
<PostPurchaseOrders>
</xsl:template>
</xsl:stylesheet>
以下是我需要将xml转换为ERP系统的内容:
<PostPurchaseOrder>
<Orders>
<OrderHeader>
<Supplier>LIY0001</Supplier>
<CustomerPoNumber>example po</CustomerPoNumber>
<OrderDate>2013-02-03</OrderDate>
<Warehouse>A1</Warehouse>
</OrderHeader>
<OrderDetails>
<StockLine>
<PurchaseOrderLine>1</PurchaseOrderLine>
<StockCode>12022</StockCode>
<OrderQty>10</OrderQty>
</StockLine>
<StockLine>
<PurchaseOrderLine>2</PurchaseOrderLine>
<StockCode>15014</StockCode>
<OrderQty>15</OrderQty>
</StockLine>
</OrderDetails>
</Orders>
</PostPurchaseOrders>
如何帮助我将我的翻译文件更改为2个密钥的分组,以便为每个供应商以及每个目的地仓库将许多行汇入一个采购订单,我们将不胜感激。
由于
答案 0 :(得分:0)
您的XSLT和示例输出之间存在一些不一致,因此我将模拟示例输出。这应该实现您正在寻找的分组:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="kOrder" match="row" use="concat(SUPPLIER, '+', DESTWHS)"/>
<xsl:template match="/*">
<PostPurchaseOrder>
<xsl:apply-templates
select="row[generate-id() =
generate-id(key('kOrder', concat(SUPPLIER, '+', DESTWHS))[1])]"
mode="group"/>
</PostPurchaseOrder>
</xsl:template>
<xsl:template match="row" mode="group">
<OrderHeader>
<Supplier>
<xsl:value-of select="SUPPLIER" />
</Supplier>
<CustomerPoNumber>
<xsl:value-of select="CUST_PO_NO" />
</CustomerPoNumber>
<OrderDate>
<xsl:value-of select="RELEASE_DATE" />
</OrderDate>
<Warehouse>
<xsl:value-of select="DESTWHS" />
</Warehouse>
</OrderHeader>
<OrderDetails>
<xsl:apply-templates select="key('kOrder', concat(SUPPLIER, '+', DESTWHS))" />
</OrderDetails>
</xsl:template>
<xsl:template match="row">
<StockLine>
<PurchaseOrderLine>
<xsl:value-of select="LINE_ITEM_NO" />
</PurchaseOrderLine>
<StockCode>
<xsl:value-of select="ITEM" />
</StockCode>
<OrderQty>
<xsl:value-of select="QTY" />
</OrderQty>
</StockLine>
</xsl:template>
</xsl:stylesheet>
在样本输入上运行时,会产生:
<PostPurchaseOrder>
<OrderHeader>
<Supplier>LIY0001</Supplier>
<CustomerPoNumber>LIY0001-2013-02-14</CustomerPoNumber>
<OrderDate>2013-02-14</OrderDate>
<Warehouse>A4</Warehouse>
</OrderHeader>
<OrderDetails>
<StockLine>
<PurchaseOrderLine>1</PurchaseOrderLine>
<StockCode>5021616</StockCode>
<OrderQty>528</OrderQty>
</StockLine>
<StockLine>
<PurchaseOrderLine>2</PurchaseOrderLine>
<StockCode>5021816</StockCode>
<OrderQty>222</OrderQty>
</StockLine>
</OrderDetails>
<OrderHeader>
<Supplier>WOR0001</Supplier>
<CustomerPoNumber>WOR0001-2013-02-14</CustomerPoNumber>
<OrderDate>2013-02-14</OrderDate>
<Warehouse>A4</Warehouse>
</OrderHeader>
<OrderDetails>
<StockLine>
<PurchaseOrderLine>9</PurchaseOrderLine>
<StockCode>650616</StockCode>
<OrderQty>129</OrderQty>
</StockLine>
</OrderDetails>
<OrderHeader>
<Supplier>WOR0001</Supplier>
<CustomerPoNumber>WOR0001-2013-02-14</CustomerPoNumber>
<OrderDate>2013-02-14</OrderDate>
<Warehouse>A5</Warehouse>
</OrderHeader>
<OrderDetails>
<StockLine>
<PurchaseOrderLine>1</PurchaseOrderLine>
<StockCode>650610</StockCode>
<OrderQty>129</OrderQty>
</StockLine>
</OrderDetails>
</PostPurchaseOrder>
答案 1 :(得分:0)
您可以使用XSLT 2.0实现以下目标:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="rows">
<PostPurchaseOrder>
<!-- Generate Orders with OrderHeader -->
<xsl:for-each-group select="row" group-by="SUPPLIER">
<Orders>
<OrderHeader>
<Supplier><xsl:value-of select="SUPPLIER" /></Supplier>
<CustomerPoNumber><xsl:value-of select="CUST_PO_NO" /></CustomerPoNumber>
<OrderDate><xsl:value-of select="RELEASE_DATE" /></OrderDate>
<Warehouse><xsl:value-of select="DESTWHS" /></Warehouse>
</OrderHeader>
<!-- Generate OrderDetails -->
<OrderDetails>
<!-- Generate StockLine -->
<xsl:for-each select="current-group()">
<StockLine>
<PurchaseOrderLine><xsl:value-of select="LINE_ITEM_NO" /></PurchaseOrderLine>
<StockCode><xsl:value-of select="ITEM" /></StockCode>
<OrderQty><xsl:value-of select="QTY" /></OrderQty>
</StockLine>
</xsl:for-each>
</OrderDetails>
</Orders>
</xsl:for-each-group>
</PostPurchaseOrder>
</xsl:template>
</xsl:stylesheet>