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

Trouble removing duplicates from a LinkedList

java iterator linked-list

For a linked list we are supposed to find duplicates in a linked list, however, the method that I've written seems to only go through once and does not remove all duplicates. Any idea on why it is ...