Selecting subelements by number

Task

Source document

<collection>
  <artist>
    <name>Robbie Williams</name>
    <cds>
      <cd>Rudebox</cd>
      <cd>Viva Life On Mars</cd>
      <cd>Lovelight (Lewis Taylor Cover)</cd>
      <cd>King Of The Bongo (Manu Chao Cover)</cd>
      <cd>Swing when you're winning</cd>
      <cd>Good Doctor</cd>
    </cds>
  </artist>
  <band>
    <name>Juli</name>
    <cds>
      <cd>Ein neuer Tag</cd>
    </cds>
  </band>
  <band>
    <name>Silbermond</name>
    <cds>
      <cd>Verschwende deine Zeit</cd>
    </cds>
  </band>
  <artist>
    <name>Michael Jackson</name>
    <cds>
      <cd>Bad</cd> 
    </cds>
  </artist>
</collection>

Challenge

Select all band or artist elements containing only one CD.

Desired selection (XML-output)

  • <band>
    • <name>Juli</name>
    • <cds>
      • <cd>Ein neuer Tag</cd>
    • </cds>
  • </band>
  • <band>
    • <name>Silbermond</name>
    • <cds>
      • <cd>Verschwende deine Zeit</cd>
    • </cds>
  • </band>
  • <artist>
    • <name>Michael Jackson</name>
    • <cds>
      • <cd>Bad</cd>
    • </cds>
  • </artist>

Exercise

Your input

Eine Lösung wäre: Lösung