简体   繁体   中英

create xsl file to transform attribute xml to element xml for import into access

I have an application on my Ipad that export data with xml. I want to import this file into MS Access 2007, but it's not possible (I guess due to the use of attributes) I guess when I can arrange a XSL file to that convert this attributes to elements, the import will work. I tried lots of XSL files from the internet, none of them worked till now. Can anyone help me?

Piece of XML file right from the ipad:

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

So this must be imported into access, I guess with an XSL file. Thanks a million for your help!!

It seems to me that the problem here is not how to transform attributes to elements, but rather how to rename the already existing field elements to the names given by their name attribute.

Caveat : I know practically nothing about MS Access, so I could be easily wrong about this. Try the following transformation:

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>

The result of applying this to your input example will be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM