Link to home
Start Free TrialLog in
Avatar of Kamilek0617
Kamilek0617

asked on

XML Attribures to Elements

I have a pretty large XML file which looks like this:

<App action="A" id="2">
          <BaseVehicle id="30218"/>  
          <Note>My Note</Note>
          <Qty>1</Qty>
          <PartType id="1684"/>  
          <MfrLabel>some label</MfrLabel>
          <Position id="30"/>  
          <Part>12345</Part>
     </App>


There may be more elements in the <app></app> but just giving an example here.

I am trying to convert this to:


<App action="A" id="2">
          <BaseVehicle>30218</BaseVehicle>  
          <Note>My Note</Note>
          <Qty>1</Qty>
          <PartType>1684</PartType>
          <MfrLabel>some label</MfrLabel>
          <Position>30</Position>
          <Part>12345</Part>
     </App>

So basically I am trying to convert attributes to elements.  I have a lot of these XML files and they are pretty big.  Anyone know of a simple way to do this? Maybe some software?  
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

You can do this using a very simple XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*[count(@*) = 1][not(node())]">
        <xsl:copy>
            <xsl:value-of select="@*"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Open in new window

Avatar of Kamilek0617
Kamilek0617

ASKER

What's XSLT?  how do I use this?
If you want a batch process to run over all your files and perform the XSLT,
I recommend that you download saxon
www.saxonica.com, home edition will do
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The answer is correct and tested
and all follow up questions have been fully answered
You have no reason to delete this question
and your argument is plain false