我们有小型数据迁移Job。在那里,我们输出到XML然后使用XSLT2.0应用转换。
方案
但是,当我们在XML的OrderHeader中添加一个子元素时。 那就是OrderLineID。然后,它没有写出预期订单的多个文件。
对于Ex: 它应该在XSLT之后写入多个文件。
SORTOIDOC_ORD-411323
SORTOIDOC_ORD-411324
SORTOIDOC_ORD-411325
抛出以下错误:
Error at xsl:result-document on line 15 of so4.xsl:
XTDE1490: Cannot write more than one result document to the same URI:
file:/C:/Data/dir/SORTOIDOC_ORD-411324.xml
Exception in component tXSLT_1
SystemID: file:/C:/Software/TOS_BD-20150908_1633-V6.0.1/workspace/xmlout/so4.xsl; Line#: 15; Column#: -1
net.sf.saxon.trans.XPathException: Cannot write more than one result document to the same URI: file:/C:/Data/dir/SORTOIDOC_ORD-411324.xml
输出XML是:
<?xml version="1.0" encoding="Windows-1252"?>
<SalesOrders xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:noNamespaceSchemaLocation="SORTOIDOC.XSD">
<Orders>
<OrderHeader>
<CustomerPoNumber>Manual Order 3</CustomerPoNumber>
<SalesForceOrderNumber>ORD-411325</SalesForceOrderNumber>
<OrderLineID>OR-1561180</OrderLineID>
</OrderHeader>
<OrderDetails>
<StockLine>
<CustomerPoLine>9999</CustomerPoLine>
<LineCancelCode/>
<StockCode>ACSH-NHH-12OZ-12</StockCode>
<StockDescription>NHH ABYSS CHIA SHAMPOO 12OZ CS</StockDescription>
<Warehouse/>
<CustomersPartNumber/>
</StockLine>
</OrderDetails>
</Orders>
</SalesOrders>
XSLT 2.O IS看起来像:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="Windows-1252" indent="yes"/>
<xsl:template match="@xsi:nil[.='true']" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<xsl:template match="@*|node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:for-each-group select="SalesOrders/Orders" group-by="OrderHeader">
<xsl:result-document href="SORTOIDOC_{OrderHeader/SalesForceOrderNumber}.xml">
<SalesOrders xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="SORTOIDOC.XSD">
<xsl:apply-templates select="current-group()"/>
</SalesOrders>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>
为什么:
将元素添加到XML OUTPUT模型会导致编写多个XML文件及其行项目时出现问题。而在添加此(OrderLineID)之前,整个场景的工作方式与预期相同。
对它的任何帮助都会得到很多赞赏吗?
提前致谢!
答案 0 :(得分:1)
听起来好像你要在OrderHeader/SalesForceOrderNumber
而不是OrderHeader
上进行分组,这样你就可以将模板更改为
<xsl:template match="/">
<xsl:for-each-group select="SalesOrders/Orders" group-by="OrderHeader/SalesForceOrderNumber">
<xsl:result-document href="SORTOIDOC_{current-grouping-key()}.xml">
<SalesOrders xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="SORTOIDOC.XSD">
<xsl:apply-templates select="current-group()"/>
</SalesOrders>
</xsl:result-document>
</xsl:for-each-group>
</xsl:template>