0

I am working on one xsl stylesheet. I am displaying title, artist and their country in tabular format. Now i need to replace country with their capitals. How can i create a mapping(key,value) and replace it in a column. Below is my sample xml.

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
  </cd>
  <cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
  </cd>
  <cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
  </cd>
  <cd>
    <title>Still got the blues</title>
    <artist>Gary Moore</artist>
    <country>UK</country>
  </cd>
</catalog>

And here is the stylesheet i am using

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html> 
<body>
  <h2>My CD Collection</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th style="text-align:left">Title</th>
      <th style="text-align:left">Artist</th>
<th style="text-align:left">Country</th>
    </tr>
    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="country"/></td>
    </tr>
    </xsl:for-each>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

I need a mapping such that whenever country name is UK it will be replaced with its capital London same with other countries. Is there somew way that i define UK as a key and London as a value so that whenever i received key as UK it will be replaced with its value. Please help.

Anam Qureshi
  • 161
  • 2
  • 8

0 Answers0