XML : Howto move an element in xml only when a value inside element matches with xslt?

This one I'm struggling with for a few day's now. I can solve little parts of the puzzle but when trying to merge it into one xslt stylesheet I'm completely lost.

The source xml looks like this (simplified)

  <tr>    <pic>      <hs>        <spot>          <posit>            <pan>28</pan>            <tilt>44</tilt>          </posit>          <id>_flare</id>        </spot>        <spot>          <posit>            <pan>6</pan>            <tilt>7</tilt>          </posit>        </spot>        <spot>          <posit>            <pan>4</pan>            <tilt>8</tilt>          </posit>          <id>Point01</id>        </spot>      </hs>      <snd>        <level>1</level>        <sound>          <loop>1</loop>        </sound>      </snd>    </pic>  </tr>    

The expected output should look like this:

  <tr>    <pic>      <hs>        <spot>          <posit>            <pan>6</pan>            <tilt>7</tilt>          </posit>        </spot>        <spot>          <posit>            <pan>4</pan>            <tilt>8</tilt>          </posit>          <id>Point01</id>        </spot>      </hs>      <snd>        <level>1</level>        <sound>          <loop>1</loop>        </sound>        <lf>            <pos>              <pan>28</pan>              <tilt>44</tilt>            </pos>            <col>#ffffff</col>        </lf>      </snd>    </pic>  </tr>    

I think it needs some explanation. Only the "spot" with an "id" that matches "_flare" in "hs" should be moved and added to the "snd" element. It also has to be reformatted from:

    <spot>      <posit>        <pan>28</pan>        <tilt>44</tilt>      </posit>      <id>_flare</id>    </spot>    

to

    <lf>        <pos>          <pan>28</pan>          <tilt>44</tilt>        </pos>        <col>#ffffff</col>    </lf>    

I appreciate a hint in the right direction to get me going again !

Regards,

AHG

No comments:

Post a Comment