Jump to content

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


QuickBooksDev

Recommended Posts

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>

Link to comment
Share on other sites

  • 2 weeks later...

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

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...