评估模板-xslt时获取内部错误

评估模板-xslt时获取内部错误,xslt,Xslt,我在将xml转换为csv时遇到问题。我遇到了一个奇怪的问题,需要帮助。 这是我的XML和XSLT,在转换时出现以下错误 “java.lang.RuntimeException:在模块”的第47行评估模板时发生内部错误,该模块位于内容为“xsl:template match=“UsrOrder”-粗体文本的行 尝试过但无法解决问题 XML 下面是我给XSLT的XML输入,它必须转换成CSV <?xml version="1.0" encoding="UTF-8"?> <d

我在将xml转换为csv时遇到问题。我遇到了一个奇怪的问题,需要帮助。
这是我的XML和XSLT,在转换时出现以下错误 “java.lang.RuntimeException:在模块”的第47行评估模板时发生内部错误,该模块位于内容为“xsl:template match=“UsrOrder”-粗体文本的行

尝试过但无法解决问题

XML 下面是我给XSLT的XML输入,它必须转换成CSV

<?xml version="1.0" encoding="UTF-8"?>
    <document>
        <businessobjects>
            <UsrOrder>
                <PlanOn>228.01</PlanOn>
                <PROG/>
                <FUND/>
                <ORGN/>
                <ACCT/>
                <Buyer/>
                <Delivery_Notes/>
                <Supplier/>
                <Line>1</Line>
                <Item_Name>NewAir AC-12000CF Airco filter</Item_Name>
                <Unit_of_Measure>STK</Unit_of_Measure>
                <Order_Date/>
                <Retrofit/>
                <Description/>
                <Product_Code/>
                <Related_Invoice_Number/>
                <Order_Attachments/>
                <Quantity>1.0000</Quantity>
                <Unit_Price>9.98</Unit_Price>
            </UsrOrder>
        </businessobjects>
    </document>
    ```    
        XSLT
        ====




<?xml version="1.0"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:csv="csv:csv">
        <xsl:output method="text" encoding="utf-8" omit-xml-declaration="yes" />
        <xsl:strip-space elements="*" />

        <xsl:variable name="delimiter" select="','" />

        <csv:columns>
            <column>Supplier</column>
            <column>FUND</column>
            <column>ORGN</column>
            <column>ACCT</column>
            <column>PROG</column>
            <column>PlanOn</column>
            <column>Delivery_Notes</column>
            <column>Buyer</column>
            <column>Line</column>
            <column>ItemName</column>
            <column>Quantity</column>
            <column>Unit_Price</column>
            <column>Unit_of_Measure</column>
            <column>Description</column>
            <column>Product_Code</column>
            <column>Category</column>
            <column>Retrofit</column>
            <column>Related_Invoice_Number</column>
            <column>OrderDate</column>
            <column>OrderAttachments</column>
        </csv:columns>

    <xsl:template match="/document/businessobjects">
            <!-- Output the CSV header -->
            <xsl:for-each select="document('')/*/csv:columns/*">
                <xsl:value-of select="."/>
                <xsl:if test="position() != last()">
                    <xsl:value-of select="$delimiter"/>
                </xsl:if>
            </xsl:for-each>
            <xsl:text>&#xa;</xsl:text>

            <!-- Output rows for each matched property -->
            <xsl:apply-templates select="UsrOrder" />
        </xsl:template>



        **<xsl:template match="UsrOrder">**
            <xsl:variable name="OrderOrderLines" select="." />

            <!-- Loop through the columns in order -->
            <xsl:for-each select="document('')/*/csv:columns/*">
                <!-- Extract the column name and value -->
                <xsl:variable name="column" select="." />
                <xsl:variable name="value" select="$OrderOrderLines/*[name() = $column]" />
                <xsl:value-of select="$value"/>
                <!-- Quote the value if required -->
               <!-- <xsl:choose>
                    <xsl:when test="contains($value, '&quot;')">
                        <xsl:variable name="x" select="replace($value, '&quot;',  '&quot;&quot;')"/>
                        <xsl:value-of select="concat('&quot;', $x, '&quot;')"/>
                    </xsl:when>
                    <xsl:when test="contains($value, $delimiter)">
                        <xsl:value-of select="concat('&quot;', $value, '&quot;')"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$value"/>
                    </xsl:otherwise>
                </xsl:choose>-->

                <!-- Add the delimiter unless we are the last expression -->
                <xsl:if test="position() != last()">
                    <xsl:value-of select="$delimiter"/>
                </xsl:if>
            </xsl:for-each>

            <!-- Add a newline at the end of the record -->
            <xsl:text>&#xa;</xsl:text>
        </xsl:template>

    </xsl:stylesheet>



228.01
1.
NewAir AC-12000CF Airco过滤器
STK
1
9.98
```    
XSLT
====
供应商
基金
奥根
会计科目
黄体脂酮素
普朗恩
送货单
买主
线
项目名称
量
单价
度量单位
描述
产品代码
类别
改造
相关发票号
訂單日期
订单附件

;
****

;
“内部错误”意味着它是XSLT处理器中的问题,而不是代码中的问题。您可以考虑检查已知的bug并升级到最新的维护版本;完成后,向供应商报告

另一种技术是尝试一种不同的XSLT处理器,看看它是否能产生任何效果。当我在当前的Saxon版本(9.9.1.5)上运行它时,我得到:


因此,如果您在样式表中解决了这个问题,失败就会消失。(所讨论的字符实际上不在第31行,它们是第46行的星号。)

我相信星号是OP为了让读者注意相关行而尝试的。您使用什么工具来运行转换?
Static error at xsl:template on line 31 column 53 of test.xsl:
  XTSE0120: No character data is allowed between top-level elements
Errors were reported during stylesheet compilation