Restructuring XML file

I have a client who would like to have drop down list added to his registration form that lists all of the provinces in the world by their country code. To that end, he gave me this file. Unfortunately, the structure of the data will not work for what I need to do. Below is the structure I'd like to have. Is there some way to automatically restructure the data, perhaps by using XSLT or something similar? Thanks!

<countries>
  <country code="US">
    <region>Alaska</region>
    <region>California</region>
  </country>
</countries>

Answers


This is easily accomplished by adding a single template to the XSLT identity transform:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="node() | @*">
       <xsl:copy>
          <xsl:apply-templates select="node() | @*" />
       </xsl:copy>
   </xsl:template>

   <xsl:template match="countries/*">
       <country code="{name()}">
          <xsl:apply-templates select="region"/>
       </country>
   </xsl:template>

</xsl:stylesheet>

Need Your Help

refresh input after ajax submit form

jquery ajax json

I searched all over but couldn't find how to refresh specific input field via js/jquery/ajax.

Wrap text in syllables TextView located in TableRow

android textview tablerow

Text that does not fit into the width cropped.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.