Jump to content

XSLT limit on for-each or how to get just first 2 of a set


QuickBooksDev

Recommended Posts

Posted

We receive an XML document that has several repeating elements. These are optional and can have from 0 to n number. We can only handle 2. How do we just get the first 2 of a set? The for-each gets all which messes up the output that we need. Below is an example of the incoming XML

 <opts length="4"><opt>Val1</opt><opt>Val2</opt><opt>Val3</opt><opt>Val4</opt></opts>

  • 2 weeks later...
Posted

Adjust the for-each's XPath so that it only matches the desired number, e.g.

<xsl:for-each select="opts/opt[position() <= 2]">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...