类似的XML不能在同一个XSLT中运行

时间:2018-03-08 17:58:37

标签: xml excel xslt

在此先感谢我有一个快速的问题,这个问题在过去的4个小时里一直在扼杀我的脑袋。

我有这个XSLT

  <xsl:when test="NAME='IES_ObtemBeneficiosEmpregados2'">
    <Worksheet ss:Name="Gastos_Pessoal">
      <Table>
        <ss:Column ss:Width="400"/>
        <ss:Column ss:Width="100"/>
        <Row ss:Index="1">
          <Cell ss:Index="1" >
            <Data ss:Type="String">RÚBRICAS
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">Valor
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="2">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Gastos com o Pessoal
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/GastosComPessoal"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="3">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Remunerações dos orgãos sociais
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/RemuneracoesOrgaosSociais"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="4">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Participação nos lucros
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/ComParticipacaoNosLucros"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="5">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Remunerações do pessoal
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/RemuneracoesPessoal"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="6">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">pós emprego
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/BeneficiosPosEmprego"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="7">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Prémios para pensões
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/PremiosParaPensoes"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="8">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Outros beneficios
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/OutrosBeneficios"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="9">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Planos de contribuições definidas pelos orgãos sociais
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/PlanosOrgaosSociais"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="10">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Planos de contribuições definidas por outros
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/PlanosAOutros"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="11">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Indemnizações
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/Indemnizacoes"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="12">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Encargos sobre remunerações
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/Encargos"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="13">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Seguros de acidentes de trabalho e doenças profissionais
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/Seguros"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="14">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Gastos de acção social
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/GastosDeAccaoSocial"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="15">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Outros gastos com pessoal
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/OutrosGastos"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="16">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">DOS QUAIS
            </Data>
          </Cell>
          <Cell ss:Index="2" >
          </Cell>
        </Row>
        <Row ss:Index="17">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Gastos com formação
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/GastosComFormacao"/>
            </Data>
          </Cell>
        </Row>
        <Row ss:Index="18">
          <Cell ss:Index="1"  >
            <Data ss:Type="String">Gastos com fardamento
            </Data>
          </Cell>
          <Cell ss:Index="2" >
            <Data ss:Type="String">
              <xsl:value-of select="VALUES/ROW/GastosComFardamento"/>
            </Data>
          </Cell>
        </Row>
      </Table>
    </Worksheet>

  </xsl:when>

为什么这个Xslt可以运行这个xml

<MODULO>
    <NAME>IES_ObtemBeneficiosEmpregados2</NAME>
    <VALUES>
      <ROW>
        <BeneficiosPosEmprego>0.00</BeneficiosPosEmprego>
        <ComParticipacaoNosLucros />
        <Encargos>227318.12</Encargos>
        <GastosComFardamento>9382.88</GastosComFardamento>
        <GastosComFormacao />
        <GastosComPessoal>1404365.80</GastosComPessoal>
        <GastosDeAccaoSocial />
        <Indemnizacoes />
        <OSComParticipacaoNosLucros />
        <OutrosBeneficios />
        <OutrosGastos>88327.73</OutrosGastos>
        <PlanosAOutros />
        <PlanosOrgaosSociais />
        <PremiosParaPensoes />
        <RemuneracoesOrgaosSociais />
        <RemuneracoesPessoal>1082034.06</RemuneracoesPessoal>
        <Seguros>6685.89</Seguros>
      </ROW>
    </VALUES>
  </MODULO>

但不是这个具有相同标签/字段/名称的XML只是不同的值

  <MODULO>
    <NAME>IES_ObtemBeneficiosEmpregados2</NAME>
    <VALUES>
      <ROW>
        <BeneficiosPosEmprego>0.00</BeneficiosPosEmprego>
        <ComParticipacaoNosLucros />
        <Encargos>3115950.69</Encargos>
        <GastosComFardamento />
        <GastosComFormacao />
        <GastosComPessoal>18012189.63</GastosComPessoal>
        <GastosDeAccaoSocial>504655.34</GastosDeAccaoSocial>
        <Indemnizacoes>47764.83</Indemnizacoes>
        <OSComParticipacaoNosLucros />
        <OutrosBeneficios />
        <OutrosGastos>55628.15</OutrosGastos>
        <PlanosAOutros />
        <PlanosOrgaosSociais />
        <PremiosParaPensoes />
        <RemuneracoesOrgaosSociais />
        <RemuneracoesPessoal>13937277.03</RemuneracoesPessoal>
        <Seguros>350913.59</Seguros>
      </ROW>
    </VALUES>
  </MODULO>

老实说,我没有看到代码有什么问题,它在运行时已经运行100%正常,现在我尝试使用不同的XML并且只是停止工作,这两种XML都是通过存储生成的SQL中的过程因此标签不可能不同。

编辑:

它给我的错误始终是一样的,

<h1>The object reference was not defined as an instance of an object</h1>

仅在我打开由XSLT创建的Excel文件时显示。

在第一次提问时,我还不够清楚。 这两个XML都不是同时运行的,它们是由存储创建的一个大型XML文件(大约5000行)自动生成的,然后这个XML运行在XSLT(我在上面提供了一小块)然后它给出了我是一个Excel文件。我已经完成了XSLT的所有功能,并且它在1个实例中工作正常,但是当我尝试生成一个不同的报告时,它只是在那段代码中爆炸(我知道通过试验和错误删除XSLT的位)看它在哪里爆炸)。

毕竟,我仍然不知道为什么类似的XML片段(只有标签内的不同值)被不同地解释。

1 个答案:

答案 0 :(得分:0)

首先,如果您将完整的XSL 发布到您的问题中而不仅仅是when块,这将非常有用。我们不知道你的其他XSL是做什么的。

话虽如此,我看到两个明显的问题:

  • 在您的XSL代码中,我看不到应该在<ss:Workbook>元素周围的<ss:Worksheet>元素。但也许它是未发布的XSL代码的一部分
  • 您必须修复命名空间! ss:命名空间中唯一的元素是<ss:Column>。但WorksheetTableRowCellData也属于此命名空间。