<for-each select="$fields">
<choose>
<when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
<otherwise>
<variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
<for-each select="$fields">
<choose>
<when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
<otherwise>
<variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>