XML - 元素的属性 - MS Access

XML - Attribute to Element - MS Access

我是 XML/XSLT 的新手,我正在学习将 XML 导入 Access 数据库。我在导入以下结构时遇到问题。输入 XML 如下(虚拟数据)

<Root>
<School Name = "ABC" Address = "XYZ"/>

<Students>

<Student ID = "123" Name = "John" Bdate = "1/1/2000">
<StudentData Address = "555 street" City = "Dummy" State = "FL"/>
</Student>

<Student ID = "234" Name = "Jane" Bdate = "1/2/2000">
<StudentData Address = "665 street" City = "Dummy" State = "FL"/>
</Student>

<Student ID = "456" Name = "Joshua" Bdate = "1/3/2000">
<StudentData Address = "775 street" City = "Dummy" State = "FL"/>
</Student>

</Students>
</Root>

我想要这种格式的输出 XML,这样当我将它加载到 Access 数据库时,我可以在一个 table.

中包含所有学生和学生数据的详细信息
<Root>
<School Name = "ABC" Address = "XYZ"/>
<Students>
<Student>
<ID>"123"</ID>
<Name>"John"</Name>
<Bdate>"1/1/2000"</Bdate>
<Address>"555 street"</Address>
<City>"Dummy"</City>
<State>"FL"</State>
</Student>

<Student>
<ID>"123"</ID>
<Name>"John"</Name>
<Bdate>"1/1/2000"</Bdate>
<Address>"555 street"</Address>
<City>"Dummy"</City>
<State>"FL"</State>
</Student>

<Student>
<ID>"123"</ID>
<Name>"John"</Name>
<Bdate>"1/1/2000"</Bdate>
<Address>"555 street"</Address>
<City>"Dummy"</City>
<State>"FL"</State>
</Student>

</Students>
</Root>

我尝试使用下面的 xsl 转换将属性转换为元素,但它没有给我想要的结果。我在一个 table 中获取学生详细信息,在另一个中获取学生数据。 我需要两者都在相同的 table 中访问数据库

<xsl:template match="*"
 <xsl:element name="{name()}">
   <xsl:for-each select="@*">
    <xsl:element name ="{name()}">
     <xsl:value-of select="."/>
    </xsl:element>
  </xsl:for-each>
  <xsl:apply-templates select="*|text()"/>
 </xsl:element>
</xsl:template>

我猜 (!) 你想做这样的事情:

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:template match="/Root">
    <Students>
        <xsl:for-each select="Students/Student">
            <Student>
                <xsl:for-each select="@* | StudentData/@*">
                    <xsl:element name="{name()}">
                        <xsl:value-of select="."/>
                    </xsl:element>
                </xsl:for-each>
            </Student>
        </xsl:for-each>
    </Students>
</xsl:template>

</xsl:stylesheet>

应用于您的输入示例,这将 return:

结果

<?xml version="1.0" encoding="UTF-8"?>
<Students>
  <Student>
    <ID>123</ID>
    <Name>John</Name>
    <Bdate>1/1/2000</Bdate>
    <Address>555 street</Address>
    <City>Dummy</City>
    <State>FL</State>
  </Student>
  <Student>
    <ID>234</ID>
    <Name>Jane</Name>
    <Bdate>1/2/2000</Bdate>
    <Address>665 street</Address>
    <City>Dummy</City>
    <State>FL</State>
  </Student>
  <Student>
    <ID>456</ID>
    <Name>Joshua</Name>
    <Bdate>1/3/2000</Bdate>
    <Address>775 street</Address>
    <City>Dummy</City>
    <State>FL</State>
  </Student>
</Students>