我需要将这些XML数据导入Access以进行进一步处理。我在这里只复制了一小部分数据:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Access Question.xsl"?>
<Catalogue>
<App action="A" id="308">
<BaseVehicle id="67"/>
<!-- 1983 Porsche 911 -->
<BodyType id="9"/>
<!-- Coupe -->
<EngineBase id="15"/>
<!-- H6 3.0L -->
<Note>OE sensor technology</Note>
<Qty>1</Qty>
<PartType id="5132"/>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position id="2172"/>
<!-- Upstream -->
<Part>101027</Part>
</App>
<App action="A" id="309">
<BaseVehicle id="67"/>
<!-- 1983 Porsche 911 -->
<BodyType id="10"/>
<!-- Convertible -->
<EngineBase id="15"/>
<!-- H6 3.0L -->
<Note>OE sensor technology</Note>
<Note>For vehicles without Start-Stop function</Note>
<Qty>1</Qty>
<PartType id="5132"/>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position id="2172"/>
<!-- Upstream -->
<Part>101027</Part>
</App>
<App action="A" id="310">
<BaseVehicle id="68"/>
<!-- 1984 Porsche 911 -->
<EngineBase id="16"/>
<!-- H6 3.2L -->
<EngineVIN id="13"/>
<!-- B -->
<Note>OE sensor technology</Note>
<Note>For vehicles without Start-Stop function</Note>
<Qty>1</Qty>
<PartType id="5132"/>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position id="2172"/>
<!-- Upstream -->
<Part>103918</Part>
</App>
<App action="A" id="311">
<BaseVehicle id="68"/>
<!-- 1984 Porsche 911 -->
<EngineBase id="1778"/>
<!-- H6 3.2L -->
<Aspiration id="5"/>
<!-- Naturally Aspirated -->
<Qty>1</Qty>
<PartType id="5132"/>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position id="2172"/>
<!-- Upstream -->
<Part>103918</Part>
</App>
</Catalogue>
对于这些数据,我使用这个XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Catalogue/App/@*">
<xsl:element name="{name()}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="Catalogue/App/Note[1]">
<Note1><xsl:apply-templates select="@*|node()"/></Note1>
</xsl:template>
<xsl:template match="Catalogue/App/Note[2]">
<Note2><xsl:apply-templates select="@*|node()"/></Note2>
</xsl:template>
<xsl:template match="Catalogue/App/Note[3]">
<Note3><xsl:apply-templates select="@*|node()"/></Note3>
</xsl:template>
<xsl:template match="Catalogue/App/Note[4]">
<Note4><xsl:apply-templates select="@*|node()"/></Note4>
</xsl:template>
<xsl:template match="Catalogue/App/Note[5]">
<Note5><xsl:apply-templates select="@*|node()"/></Note5>
</xsl:template>
<xsl:template match="Catalogue/App/Note[6]">
<Note6><xsl:apply-templates select="@*|node()"/></Note6>
</xsl:template>
<xsl:template match="Catalogue/App/Note[7]">
<Note7><xsl:apply-templates select="@*|node()"/></Note7>
</xsl:template>
<xsl:template match="Catalogue/App/Note[8]">
<Note8><xsl:apply-templates select="@*|node()"/></Note8>
</xsl:template>
<xsl:template match="Catalogue/App/Note[9]">
<Note9><xsl:apply-templates select="@*|node()"/></Note9>
</xsl:template>
<xsl:template match="Catalogue/App/Note[10]">
<Note10><xsl:apply-templates select="@*|node()"/></Note10>
</xsl:template>
<xsl:template match="Catalogue/App/Note[11]">
<Note11><xsl:apply-templates select="@*|node()"/></Note11>
</xsl:template>
<xsl:template match="Catalogue/App/Note[12]">
<Note12><xsl:apply-templates select="@*|node()"/></Note12>
</xsl:template>
<xsl:template match="Catalogue/App/Note[13]">
<Note13><xsl:apply-templates select="@*|node()"/></Note13>
</xsl:template>
<xsl:template match="Catalogue/App/Note[14]">
<Note14><xsl:apply-templates select="@*|node()"/></Note14>
</xsl:template>
<xsl:template match="Catalogue/App/Note[15]">
<Note15><xsl:apply-templates select="@*|node()"/></Note15>
</xsl:template>
</xsl:stylesheet>
转换后,它看起来像这样:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Catalogue>
<App>
<action>A</action>
<id>308</id>
<BaseVehicle>67</BaseVehicle>
<!-- 1983 Porsche 911 -->
<BodyType>9</BodyType>
<!-- Coupe -->
<EngineBase>15</EngineBase>
<!-- H6 3.0L -->
<Note1>OE sensor technology</Note1>
<Qty>1</Qty>
<PartType>5132</PartType>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position>2172</Position>
<!-- Upstream -->
<Part>101027</Part>
</App>
<App>
<action>A</action>
<id>309</id>
<BaseVehicle>67</BaseVehicle>
<!-- 1983 Porsche 911 -->
<BodyType>10</BodyType>
<!-- Convertible -->
<EngineBase>15</EngineBase>
<!-- H6 3.0L -->
<Note1>OE sensor technology</Note1>
<Note2>For vehicles without Start-Stop function</Note2>
<Qty>1</Qty>
<PartType>5132</PartType>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position>2172</Position>
<!-- Upstream -->
<Part>101027</Part>
</App>
<App>
<action>A</action>
<id>310</id>
<BaseVehicle>68</BaseVehicle>
<!-- 1984 Porsche 911 -->
<EngineBase>16</EngineBase>
<!-- H6 3.2L -->
<EngineVIN>13</EngineVIN>
<!-- B -->
<Note1>OE sensor technology</Note1>
<Note2>For vehicles without Start-Stop function</Note2>
<Qty>1</Qty>
<PartType>5132</PartType>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position>2172</Position>
<!-- Upstream -->
<Part>103918</Part>
</App>
<App>
<action>A</action>
<id>311</id>
<BaseVehicle>68</BaseVehicle>
<!-- 1984 Porsche 911 -->
<EngineBase>1778</EngineBase>
<!-- H6 3.2L -->
<Aspiration>5</Aspiration>
<!-- Naturally Aspirated -->
<Qty>1</Qty>
<PartType>5132</PartType>
<!-- Oxygen Sensor -->
<MfrLabel>Sensor</MfrLabel>
<Position>2172</Position>
<!-- Upstream -->
<Part>103918</Part>
</App>
</Catalogue>
问题是当我使用XSLT转换将这个XML导入Access时,元素&#34; Aspiration&#34;和&#34; EngineVIN&#34;没有进口。当我尝试以相同的方式将其导入Excel时,它工作正常。有谁知道为什么这会发生在Access以及如何解决它? 无论如何我找到了如何解决问题。我需要添加New App id =&#34; 0&#34;包含其他App-s中的所有元素名称,如Aspiration,EngineVIN等...如何添加这个新的App id =&#34; 0&#34;在现有数据的基础上?