XSLT在MS ACCESS导入中更改XML

时间:2014-05-23 12:46:11

标签: xml xslt ms-access-2007

我需要将xml文件导入到access中,我应该进行转换(XML - > XML)并执行Access调用XSLT文件。

然后我的源文件是:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<F1Project>
<File>piloti.php</File>
<Fetchdate>2014-05-23 11:37:41</Fetchdate>
<IdTeam>614</IdTeam>
<Training>
<TrainingFirstSkill>accelerazione</TrainingFirstSkill>
<TrainingSecondSkill>tecnica</TrainingSecondSkill>
</Training>
<TalentScout>
<TalentScoutLevel>16</TalentScoutLevel>
<TalentScoutFunding>25000</TalentScoutFunding>
</TalentScout>
<Drivers>
<Driver Index="1">
<DriverId>357352</DriverId>
<DriverName>Doukas</DriverName>
<DriverSurname>Nastos</DriverSurname>
<DriverDPI>55344</DriverDPI>
</Driver>
<Driver Index="2">
<DriverId>539134</DriverId>
<DriverName>Jurica</DriverName>
<DriverSurname>Andonovic</DriverSurname>
<DriverDPI>1406</DriverDPI>
</Driver>
<Driver Index="3">
<DriverId>473147</DriverId>
<DriverName>Tommaso</DriverName>
<DriverSurname>Galea</DriverSurname>
<DriverDPI>5553</DriverDPI>
</Driver>
</Drivers>
</F1Project>

将其导入MSAccess,它为每个元素创建了几个表,到目前为止一切正常。

我想在每个表中都有元素&#34;数据&#34; (原始xml仅在表中报告)。

然后出现&#34; index&#34;的问题。并不总是3,可能更多或更少,甚至在这种情况下需要每个元素中的日期......

预期产出:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<F1Project>
<File>piloti.php</File>
<Fetchdate>2014-05-23 11:37:41</Fetchdate>
<IdTeam>614</IdTeam>
<Training>
***<Fetchdate>2014-05-23 11:37:41</Fetchdate>***
<TrainingFirstSkill>accelerazione</TrainingFirstSkill>
<TrainingSecondSkill>tecnica</TrainingSecondSkill>
</Training>
<TalentScout>
***<Fetchdate>2014-05-23 11:37:41</Fetchdate>***
<TalentScoutLevel>16</TalentScoutLevel>
<TalentScoutFunding>25000</TalentScoutFunding>
</TalentScout>
<Drivers>
<Driver Index="1">
***<Fetchdate>2014-05-23 11:37:41</Fetchdate>***
<DriverId>357352</DriverId>
<DriverName>Doukas</DriverName>
<DriverSurname>Nastos</DriverSurname>
<DriverDPI>55344</DriverDPI>
</Driver>
<Driver Index="2">
***<Fetchdate>2014-05-23 11:37:41</Fetchdate>***
<DriverId>539134</DriverId>
<DriverName>Jurica</DriverName>
<DriverSurname>Andonovic</DriverSurname>
<DriverDPI>1406</DriverDPI>
</Driver>
<Driver Index="3">
***<Fetchdate>2014-05-23 11:37:41</Fetchdate>***
<DriverId>473147</DriverId>
<DriverName>Tommaso</DriverName>
<DriverSurname>Galea</DriverSurname>
<DriverDPI>5553</DriverDPI>
</Driver>
***<Driver Index="n">
<Fetchdate>2014-05-23 11:37:41</Fetchdate>
<DriverId>####</DriverId>
<DriverName>xxxx</DriverName>
<DriverSurname>yyyy</DriverSurname>
<DriverDPI>####</DriverDPI>
</Driver>***
</Drivers>
</F1Project>

谁能帮助我生成满足我需求的XSLT? 我希望我已经清楚地解释了我的问题 感谢

1 个答案:

答案 0 :(得分:0)

您最需要identity transform,它只是将输入XML复制到输出文档。除此之外,您还可以捕获相关的子节点<Training/><Driver/>,并将所需的<Fetchdate/>附加到它们。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="Training|Driver">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:copy-of select="ancestor::F1Project/Fetchdate"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

有两个模板:一个匹配每个节点,另一个匹配需要添加<Fetchdate/>的节点。它们都将现有节点复制到输出文档,但在第二个节点中,它复制:

  1. 节点的任何属性
  2. <Fetchdate/>,它通过访问其<F1Project/>祖先并查找其日期来找到
  3. 子节点
  4. 该样式表在您的示例数据上运行时会生成此输出:

    <F1Project>
      <File>piloti.php</File>
      <Fetchdate>2014-05-23 11:37:41</Fetchdate>
      <IdTeam>614</IdTeam>
      <Training>
        <Fetchdate>2014-05-23 11:37:41</Fetchdate>
        <TrainingFirstSkill>accelerazione</TrainingFirstSkill>
        <TrainingSecondSkill>tecnica</TrainingSecondSkill>
      </Training>
      <TalentScout>
        <TalentScoutLevel>16</TalentScoutLevel>
        <TalentScoutFunding>25000</TalentScoutFunding>
      </TalentScout>
      <Drivers>
        <Driver Index="1">
          <Fetchdate>2014-05-23 11:37:41</Fetchdate>
          <DriverId>357352</DriverId>
          <DriverName>Doukas</DriverName>
          <DriverSurname>Nastos</DriverSurname>
          <DriverDPI>55344</DriverDPI>
        </Driver>
        <Driver Index="2">
          <Fetchdate>2014-05-23 11:37:41</Fetchdate>
          <DriverId>539134</DriverId>
          <DriverName>Jurica</DriverName>
          <DriverSurname>Andonovic</DriverSurname>
          <DriverDPI>1406</DriverDPI>
        </Driver>
        <Driver Index="3">
          <Fetchdate>2014-05-23 11:37:41</Fetchdate>
          <DriverId>473147</DriverId>
          <DriverName>Tommaso</DriverName>
          <DriverSurname>Galea</DriverSurname>
          <DriverDPI>5553</DriverDPI>
        </Driver>
      </Drivers>
    </F1Project>
    

    这是一个简单的转变。如果您有任何疑问,请询问。