本文介绍了将以属性为中心的xml转换为以元素为中心的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将下面的XML文件转换为以元素为中心的文件?也许使用在线工具?不需要使用VB什么?我需要将此XML导入到Access,但无法这样做,因为Access需要以元素为中心的XML。

Is there a way to convert following XML file to element-centric file? Perhaps using an online tool? Without requiring to use VB anything? I need to import this xml to Access, but unable to do so because Access requires element-centric 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>


推荐答案

使用以下内容作为invoices.xsl

Use following as your 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>

这篇关于将以属性为中心的xml转换为以元素为中心的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 08:12