Hi

Im new to XSL. Im trying to read a XML file that has identical node names with different values.

<mondial>
  <country car_code="MK" capital="cty-cid-cia-Macedonia-Skopje">
    <name>Macedonia</name>
    <indep_date>1991-09-17</indep_date>
    <government>emerging democracy</government>
    <encompassed continent="europe" percentage="100"/>
    <ethnicgroups percentage="22">Albanian</ethnicgroups>
    <ethnicgroups percentage="2">Serb</ethnicgroups>
    <ethnicgroups percentage="65">Macedonian</ethnicgroups>
    <ethnicgroups percentage="4">Turkish</ethnicgroups>
    <ethnicgroups percentage="3">Gypsy</ethnicgroups>
    <religions percentage="30">Muslim</religions>
    <religions percentage="67">Christian Orthodox</religions>
    <languages percentage="21">Albanian</languages>
    <languages percentage="70">Macedonian</languages>
    <languages percentage="3">Turkish</languages>
    <languages percentage="3">Serbian</languages>
  <city id="cty-cid-cia-Macedonia-Skopje" country="MK">
    <name/>
   </city>
 </country>
</mondial>

My problem: I am using xsl:for to obtain the ethincgroups. My xsl only grabs the first "ethnicgroups" on the tree. How can I get it to reall all ethnicgroups.

XSL code:

<xsl:key name"eth" match="country" use="ethnicgroups"

  <xsl:template match="/"

    <xsl:for-each select="//country[generate-id() = generate-id('eth', ethnicgroups)[1]]">

   <xsl:value-of select="etnicgroups"

The result I get is Albania. How do I also get Serb, Macedonian, Turkish, Gypsy?

Thanks for your responce Pritaeas. I tried for-each but it did not return any values, not even Albanian.

Provide a sample XML document that you're trying to produce. If we can see what structure you're trying to produce with your transformation, we can can provide a solution. We've got your input document, but what are you trying to produce? Give us a sample output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.