XSLT更改MS ACCESS导入中的XML [英] XSLT to change XML in MS ACCESS import

查看:61
本文介绍了XSLT更改MS ACCESS导入中的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to import the xml file into access and I should do the transformations (XML -> XML) and to do that Access calls an XSLT file.

然后我的源文件是:

<?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,它为每个元素创建多个表,到目前为止一切正常.

Importing it into MSAccess, it creates several tables for each element and so far everything is ok.

我希望在每个表中都有元素数据"(原始xml仅在表中报告).

I would like to have in each table the element "data" (which the original xml is reported only in a table).

然后就是索引"的问题,该索引并不总是3,或多或少,甚至在这种情况下,每个元素中都需要日期...

Then there is the problem of "index" which are not always 3, may be more or less, and even in this case would need the date in each element ...

预期输出:

<?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? 我希望我已经清楚地说明了我的问题 谢谢

Who can help me to generate an XSLT that meets my needs? I hope I have explained my problem clearly thanks

推荐答案

您通常需要身份转换,它只是将输入XML复制到输出文档中.除此之外,您还可以捕获相关的子节点<Training/><Driver/>,并将所需的<Fetchdate/>附加到它们.

You mostly need the identity transform, which simply copies the input XML to the output document. Apart from that, you can catch the relevant child nodes, <Training/> and <Driver/>, and attach the needed <Fetchdate/> to them.

<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/>的节点匹配.他们都将现有节点复制到输出文档,但是在第二个节点中,它将复制:

There are two templates: one that matches every node, and one that matches the nodes that need the <Fetchdate/> added. They both copy the existing nodes to the output document, but in the second one, it copies:

  1. 节点的任何属性
  2. <Fetchdate/>,它是通过访问其<F1Project/>祖先并找到其日期而找到的
  3. 子节点
  1. any attributes of the node
  2. the <Fetchdate/>, which it finds by visiting its <F1Project/> ancestor and finding its date
  3. the children nodes

在示例数据上运行时,该样式表会产生以下输出:

That stylesheet produces this output when run on your example data:

<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>

这是一个简单的转换.如有任何疑问,请询问.

This is a simple transformation. If you have any questions, please ask.

这篇关于XSLT更改MS ACCESS导入中的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆