我是xml和xsl的新手,所以我将尽力解释我的问题。我有这种类型的xml,它是以属性为中心的,并且不会导入Access。如何将属性数据转换为元素数据?这是我拥有的xml的一部分:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Catalogue version="3.0">
<App action="A" id="1">
<BaseVehicle id="1"/>
<Note>Use Separate Enclosed Connector</Note>
<Note>Slightly longer than original</Note>
<Qty>1</Qty>
<PartType id="8852"/>
<MfrLabel>CleanWipe</MfrLabel>
<Position id="104"/>
<Part>18CW</Part>
</App>
<App action="A" id="2">
<BaseVehicle id="1"/>
<BodyType id="6"/>
<Note>Use Separate Enclosed Connector</Note>
<Qty>1</Qty>
<PartType id="8852"/>
<MfrLabel>SuperWipe</MfrLabel>
<Position id="30"/>
<Part>22SW</Part>
</App>
</Catalogue>
这是我用于将xml导入Access的xsl(我不太了解它的工作原理,我在stackflow上找到了它):
<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:stylesheet>
问题是我丢失了应用程序ID。有没有一种方法可以导入Access数据并在列中包含App ID?我的“注释”行也有问题,因为每个“应用程序”有多个注释行,因此无法导入所有注释行。您有建议如何导入此xml而不丢失任何数据吗?谢谢你们!!!
编辑:这是我希望在Access中导入后的列表:
ID BaseVehicle注释数量PartType MfrLabel位置零件BodyType
1 1比原来的长度稍长1 8852 CleanWipe 104 18CW
1 1使用独立的封闭式连接器1 8852 CleanWipe 104 18CW
2 1使用独立的封闭式连接器1 8852 SuperWipe 30 22SW 6
或像这样:
ID BaseVehicle注释数量PartType MfrLabel位置零件BodyType
1 1稍长一些.. +使用单独的E .. 1 8852 CleanWipe 104 18CW
2 1使用单独的封闭式连接器1 8852 SuperWipe 30 22SW 6
问题是我无法使其导入列ID并在单独的行中合并注释或导入非第一注释...
我找到了问题的答案。这是我正在寻找的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>
这样,所有属性都将转换为元素,并且所有重复的“注释”元素都将根据其在“应用”中的位置而重命名(最多15次)。但是由于我知道不会超过10次,因此可以正常工作。15只是出于预防目的。转换后的外观如下:
<?xml version="1.0" encoding="UTF-8"?>
<Catalogue>
3.0
<App>
<action>A</action>
<id>1</id>
<BaseVehicle>1</BaseVehicle>
<Note1>Use Separate Enclosed Connector</Note1>
<Note2>Slightly longer than original</Note2>
<Qty>1</Qty>
<PartType>8852</PartType>
<MfrLabel>CleanWipe</MfrLabel>
<Position>104</Position>
<Part>18CW</Part>
</App>
<App>
<action>A</action>
<id>2</id>
<BaseVehicle>1</BaseVehicle>
<BodyType>6</BodyType>
<Note1>Use Separate Enclosed Connector</Note1>
<Qty>1</Qty>
<PartType>8852</PartType>
<MfrLabel>SuperWipe</MfrLabel>
<Position>30</Position>
<Part>22SW</Part>
</App>
</Catalogue>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句