XSLT - How to select top a to top b

Posted by user812241 on Stack Overflow See other posts from Stack Overflow or by user812241
Published on 2011-06-23T13:15:55Z Indexed on 2011/06/23 16:23 UTC
Read the original article Hit count: 205

Filed under:

how can I extract the first 2 C-Values ('Baby' and 'Cola') where B is 'RED'. Input instance is:

<Root>
  <A>
    <B>BLACK</B>
    <C>Apple</C>
  </A>
  <A>
    <B>RED</B>
    <C>Baby</C>
  </A>
  <A>
    <B>GREEN</B>
    <C>Sun</C>
  </A>
  <A>
    <B>RED</B>
    <C>Cola</C>
  </A>
  <A>
    <B>RED</B>
    <C>Mobile</C>
  </A>
</Root>

Output instance must be:

<Root>
  <D>Baby</D>
  <D>Cola</D>
</Root>

I thought about the combination of for-each and global variables. But in XSLT it is not possible to change the value for a global variable to break the for-each. I have no idea anymore.

© Stack Overflow or respective owner

Related posts about xslt