Reputation: 1257
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?
Upvotes: 1
Views: 2013
Reputation: 338128
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.
Upvotes: 3