How to export Excel spreadsheets to XML, but attributes have been instead elements?
I save a spreadsheets from Excel to XML in this view:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<companies>
<company>
<employee>
<code>1</code>
<name/>
<street>14th street</street>
<houseno>1</houseno>
<areacode>1050 DD</areacode>
<place>开发者_高级运维;NoWhere</place>
<phone>0100 987654</phone>
</employee>
</company>
</companies>
But I need this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<companies>
<company>
<employee code="1" name="" street="14th street"  houseno="1" areacode="1050 DD" place="NoWhere" phone="0100 987654">
</employee>
</company>
</companies>
Tell me please how to solve the problem?
This XSLT 1.0 stylesheet would do it (try it here with your sample XML).
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" />
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*" />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="employee">
    <xsl:copy>
      <xsl:apply-templates select="*" />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="employee/*">
    <xsl:attribute name="{name()}">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>
Now it depends onyour environment how you can use it. There are several tools and libraries available that provide XSLT support.
You XSLT to transform your XML data.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论