将以属性为中心的xml转换为以元素为中心

时间:2014-03-17 02:30:46

标签: html xml ms-access xslt html-table

有没有办法将以下XML文件转换为以元素为中心的文件?也许使用在线工具?无需使用VB任何东西?我需要将此xml导入Access,但无法执行此操作,因为Access需要以元素为中心的xml。

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="invoices.xsl"?>
<invoices>
   <invoice number="25" date="February 28, 2001">
      <patient firstname="Jeff" familyname="Smith" SSN="123456789">
         <phone type="home" number="123-4567890"/>
         <phone number="321-76543321" type="work"/>
         <address type="home" line1="123 Street" city="City" state="US" zip="12345"/>
      </patient>
      <insurance name="Humongous First Medical Insurance" plannumber="12345" planname="The Client Company">
         <phone number="098-76543321"/>
         <address type="business" line1="321 Street" city="City" state="US" zip="54321"/>
      </insurance>
      <procedure code="123" name="Cleaning nose" cost="50.00" insurance_estimate="50.00"/>
      <procedure code="124" name="Tarot reading of illnesses" cost="150.00" insurance_estimate="120.00"/>
      <procedure code="125" name="Just for fun" cost="100.00" insurance_estimate="80.00"/>
   </invoice>
   <invoice number="27" date="February 28, 2001">
      <patient firstname="James" familyname="Smith" SSN="123456765">
         <phone type="home" number="123-4562245"/>
         <address type="home" line1="432 Street" city="City" state="US" zip="12343"/>
      </patient>
      <insurance name="Humongous Second Medical Insurance" plannumber="3455" planname="Another Client Company">
         <phone number="098-76543321"/>
         <address type="business" line1="344 Street" city="Some City" state="US" zip="54323"/>
      </insurance>
      <procedure code="123" name="Cleaning nose" cost="50.00" insurance_estimate="50.00"/>
      <procedure code="124" name="Tarot reading of illnesses" cost="150.00" insurance_estimate="120.00"/>
   </invoice>
   <invoice number="29" date="February 28, 2001">
      <patient firstname="Neil" familyname="Smith" SSN="123456345">
         <phone type="home" number="125-4345890"/>
         <address type="home" line1="187 Street" city="Lost City" state="US" zip="42145"/>
      </patient>
      <insurance name="Humongous Third Medical Insurance" plannumber="12345" planname="The Lost City Client Company">
         <phone number="198-76345321"/>
         <address type="business" line1="342 Street" city="Completely Lost City" state="US" zip="111111-0000"/>
      </insurance>
      <procedure code="123" name="Cleaning nose" cost="50.00" insurance_estimate="50.00"/>
      <procedure code="125" name="Maybe they wouldn't see this line..." cost="100.00" insurance_estimate="80.00"/>
   </invoice>
</invoices>

1 个答案:

答案 0 :(得分:2)

将以下内容用作invoices.xsl

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

<xsl:template match="node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

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

</xsl:stylesheet>