XML : Transform xml to xml using XSLT - Advices

I have one XML file :

  <?xml version="1.0" encoding="utf-8" standalone="no"?>  <Cars>      <Car>          <Color>Blue</Color>          <Model>Car2</Model>          <Year>1988</Year>          <Speed>250</Speed>      </Car>      <Car>          <Color>Blue</Color>          <Model>Car2</Model>          <Year>1988</Year>          <Speed>250</Speed>      </Car>  </Cars>    

I want to transform this using XSLT for have :

  <?xml version="1.0" encoding="utf-8" standalone="no"?>  <vehicles>      <vehicle>          <vehicleColor>Blue</vehicleColor>          <vehicleModel>Car2</vehicleModel>          <vehicleYear>1988</vehicleYear>          <vehicleSpeed>250</vehicleSpeed>      </vehicle>      <vehicle>          <vehicleColor>Blue</vehicleColor>          <vehicleModel>Car2</vehicleModel>          <vehicleYear>1988</vehicleYear>          <vehicleSpeed>250</vehicleSpeed>      </vehicle>  </vehicles>    

My XSLT File :

  <?xml version="1.0" encoding="UTF-8"?>  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">        <xsl:template match="/">            <vehicles>              <xsl:for-each select="Cars/Car">                    <vehicle>                      <vehicleColor><xsl:value-of select="Color"/></vehicleColor>                      <vehicleModel><xsl:value-of select="Model"/></vehicleModel>                      <vehicleYear><xsl:value-of select="Year"/></vehicleYear>                      <vehicleSpeed><xsl:value-of select="Speed"/></vehicleSpeed>                  </vehicle>                </xsl:for-each>          </vehicles>        </xsl:template>    </xsl:stylesheet>    

It work but I want to know if my XSLT file is correct and if no, I want advices.

Also, in my output file generated with XSLT, I have not the XML header. Why ?

No comments:

Post a Comment