【问题标题】:Error Creating Excel XML with XSLT - Bad Index Value使用 XSLT 创建 Excel XML 时出错 - 索引值错误
【发布时间】:2015-10-03 03:35:00
【问题描述】:

使用 XSLT 将 XML 转换为 Excel 并在尝试在 Excel 中打开生成的 XML 时收到以下错误。根据研究和相关帖子Error : Exporting excel through XSLT,错误似乎是由于使用 MergeDown() 后行/单元格索引不正确。出于某种原因,在未指定任何索引的情况下使用 MergeAcross() 就可以正常工作。

我还没有找到一种方法来索引行,因为特定的单元格被合并到一个不同的数字上,这取决于每个单元格可能不同的变量值,所以在我的 xslt 中没有简单的方法定义我找到的每一行的索引应该是什么。请在下面找到 xslt、源 xml 和所需的 xml。提前感谢您的帮助。

ERROR in ExcelWorkbook description
REASON: Bad Value
FILE:   results_output.xmlaj
GROUP:  Row
TAG:    Cell
ATTRIB: Index
VALUE:  0

源 XML:

<analysis>
 <sample>
    <assay name="Bpm" type="presence/absence">


        <amplicon reads="2">


            <significance flag="insufficient breadth of coverage"/>


        </amplicon>


    </assay>

    <assay name="Bpm_M" type="presence/absence">


        <amplicon reads="43961">


            <snp>


                <snp_call count="105" percent="100.0">C</snp_call>


                <base_distribution C="105"/>


            </snp>


            <snp>


                <snp_call count="5016" percent="94.48106988133358">T</snp_call>


                <base_distribution C="6" G="287" T="5016"/>


            </snp>


            <snp>


                <snp_call count="16833" percent="98.76202769302981">C</snp_call>


                <base_distribution A="30" C="16833" G="178" T="2" _="1"/>


            </snp>

        </amplicon>


    </assay>

    <assay name="Bpm_1" type="presence/absence">


        <amplicon reads="0">


            <significance flag="no coverage"/>


        </amplicon>


    </assay>

</sample>
<sample>


    <assay name="Bpm" type="presence/absence">


        <amplicon reads="0">


            <significance flag="no coverage"/>


        </amplicon>


    </assay>

    <assay name="Bpm_M" type="presence/absence">


        <amplicon reads="0">


            <significance flag="no coverage"/>


        </amplicon>


    </assay>

    <assay name="Bpm_1" type="presence/absence">


        <amplicon reads="49177">


            <snp>


                <snp_call count="26322" percent="99.90890457754497">A</snp_call>


                <base_distribution A="26322" C="14" G="2" T="8"/>


            </snp>


            <snp>


                <snp_call count="46825" percent="99.95303861506606">T</snp_call>


                <base_distribution A="1" C="4" G="17" T="46825"/>


            </snp>


        </amplicon>


     </assay>
 </sample>
</analysis>

XSLT:

<Table>
                    <Column ss:AutoFitWidth="0" ss:Width="210" />

                    <Row>
                            <Cell>
                                    <Data ss:Type="String">
                                    </Data>
                            </Cell>
                    </Row>
                    <Row ss:AutoFitHeight="0" ss:Height="18">
                            <Cell>
                                    <Data ss:Type="String">
                                    </Data>
                            </Cell>

                            <Cell ss:MergeAcross="count(//analysis/sample[position()=1]/assay) - 1">
                                    <Data ss:Type="String">Distro                   
                                    </Data>
                            </Cell>
                    </Row>
                    <Row ss:AutoFitHeight="0" ss:Height="18">

                            <Cell>
                                    <Data ss:Type="String">Sample Name                  
                                    </Data>
                            </Cell>

                    <xsl:for-each select="//sample[position()=1]/assay">


                            <Cell>
                                    <Data ss:Type="String">
                                        <xsl:value-of select="@name" />             
                                    </Data>
                            </Cell>

                    </xsl:for-each>

                    </Row>

            <xsl:for-each select="//analysis/sample">

                    <Row>

                        <xsl:variable name="max">
                            <xsl:for-each select="assay">
                                <xsl:sort select="count(amplicon/snp)" data-type="number" order="descending"/>
                                <xsl:if test="position() = 1"><xsl:value-of select="count(amplicon/snp)"/></xsl:if>
                            </xsl:for-each>
                        </xsl:variable>


                        <xsl:choose>
                            <xsl:when test="$max &gt; 0">

                                <Cell ss:MergeDown="{$max - 1}">
                                        <Data ss:Type="String">
                                            <xsl:value-of select="@name" />
                                        </Data>
                                </Cell>

                            </xsl:when>
                            <xsl:otherwise>

                                <Cell>
                                        <Data ss:Type="String">
                                            <xsl:value-of select="@name" />
                                        </Data>
                                </Cell>

                            </xsl:otherwise>
                        </xsl:choose>

                    </Row>

            </xsl:for-each>
</Table>

所需的 XML:

<Table>
     <Column ss:AutoFitWidth="0" ss:Width="210"/>
     <Row>
        <Cell>
           <Data ss:Type="String"/>
        </Cell>
     </Row>
     <Row ss:AutoFitHeight="0" ss:Height="18">
        <Cell>
           <Data ss:Type="String"/>
        </Cell>
        <Cell ss:StyleID="s22" ss:MergeAcross="2">
           <Data ss:Type="String">Dist                  
           </Data>
        </Cell>
     </Row>
     <Row ss:AutoFitHeight="0" ss:Height="18">
        <Cell>
           <Data ss:Type="String">Sample Name</Data>
        </Cell>
        <Cell>
           <Data ss:Type="String">Bpm</Data>
        </Cell>
        <Cell>
           <Data ss:Type="String">Bpm_M</Data>
        </Cell>
        <Cell>
           <Data ss:Type="String">Bpm_1</Data>
        </Cell>
     </Row>
     <Row>
        <Cell ss:MergeDown="2">
           <Data ss:Type="String">Sample 1</Data>
        </Cell>
     </Row>
     <Row>
        <Cell ss:MergeDown="1">
           <Data ss:Type="String">Sample 2</Data>
        </Cell>
     </Row>
</Table>

【问题讨论】:

    标签: xml excel xslt


    【解决方案1】:

    您正在使用常规属性中的表达式:

     <Cell ss:MergeAcross="count(//analysis/sample[position()=1]/assay) - 1">
    

    尝试将表达式放入花括号

     <Cell ss:MergeAcross="{count(//analysis/sample[position()=1]/assay) - 1}">
    

    或者使用 xsl:attribute

    <xsl:attribute name="ss:MergeAcross">
      <xsl:value-of select="count(//analysis/sample[position()=1]/assay) - 1"/>
    </xsl:attribute>
    

    【讨论】:

    • 试过了,仍然收到同样的错误。我确定问题出在 MergeDown 上,因为当我删除单个 ss:MergeDown="{$max - 1}" 时,生成的 xml 在 excel 中正确打开,没有错误。
    猜你喜欢
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多