【问题标题】:create xsl file to transform attribute xml to element xml for import into access创建 xsl 文件以将属性 xml 转换为元素 xml 以导入访问
【发布时间】:2015-10-20 15:52:41
【问题描述】:

我的 Ipad 上有一个使用 xml 导出数据的应用程序。我想将此文件导入 MS Access 2007,但这是不可能的(我猜是由于使用了属性)我想当我可以安排一个 XSL 文件来将此属性转换为元素时,导入将起作用。我从互联网上尝试了很多 XSL 文件,但到目前为止都没有工作。谁能帮帮我?

来自 ipad 的 XML 文件:

<?xml version="1.0"?>
<form name="AppVIEW">
<field name="Date" type="date"/>
<field name="Hospital" type="text"/>
<field name="ID" type="text"/>
<field name="VisitType" type="text"/>
<field name="Specialisation" type="text"/>
<field name="ContactName" type="text"/>
<field name="ContactTel" type="text"/>
<field name="ContactMail" type="text"/>
<field name="ShortText" type="text"/>
<field name="Actions" type="text"/>
<record name="OLVG">
<field name="Date">2015-10-14</field>
<field name="Hospital">OLVG</field>
<field name="ID">1</field>
<field name="VisitType">Handover</field>
<field name="Specialisation">SYS1</field>
<field name="ContactName">Nick</field>
<field name="ContactTel">0365425653</field>
<field name="ContactMail">Nick@new.nl</field>
<field name="ShortText">Dit is een test</field>
<field name="Actions">Geen verdere acties nodig</field>
</record>
</form>

所以这必须导入到访问中,我猜是使用 XSL 文件。感谢您的帮助!

【问题讨论】:

  • 至少没有您想要的 XML 格式,也没有一些迹象表明您已经开始自己解决这个问题并且卡在某个点上,这很难回答。

标签: xml ms-access xslt import


【解决方案1】:

在我看来,这里的问题不是如何将属性转换为元素,而是如何将已经存在的field 元素重命名为其name 属性给出的名称。

警告:我对 MS Access 几乎一无所知,所以我很容易在这方面犯错。尝试以下转换:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/form">
    <table>
        <xsl:apply-templates select="record"/>
    </table>
</xsl:template>

<xsl:template match="record">
    <row>
        <xsl:apply-templates select="field"/>
    </row>
</xsl:template>

<xsl:template match="field">
    <xsl:element name="{@name}">
        <xsl:value-of select="."/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>

将此应用于您的输入示例的结果将是:

<?xml version="1.0" encoding="UTF-8"?>
<table>
   <row>
      <Date>2015-10-14</Date>
      <Hospital>OLVG</Hospital>
      <ID>1</ID>
      <VisitType>Handover</VisitType>
      <Specialisation>SYS1</Specialisation>
      <ContactName>Nick</ContactName>
      <ContactTel>0365425653</ContactTel>
      <ContactMail>Nick@new.nl</ContactMail>
      <ShortText>Dit is een test</ShortText>
      <Actions>Geen verdere acties nodig</Actions>
   </row>
</table>

【讨论】:

    猜你喜欢
    • 2016-03-13
    • 2017-06-17
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多