XSLT Transformer ThrowsException:无法将多个结果文档写入同一 URI

XSLT Transformer ThrowsException : Cannot write more than one result document to the same URI

我们有小型数据迁移作业。在那里,我们输出到 XML,然后使用 XSLT2.0 应用转换。

场景

但是,当我们在 XML 的 OrderHeader 中添加一个子元素时。 即 OrderLineID。然后,它不是写入预期顺序的多个文件。

例如: 它应该在 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 看起来像:

<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) 之前整个场景按预期工作。

如有任何帮助,我们将不胜感激?

提前致谢!

听起来好像您想在 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>