xslt logic to print xml element in array

Below is the piece of code which is printing eligibility section in json format after processing XML but it is not giving me the desired output.

my XSLT is applied on the XML output and then my application is changing this output to JSON.

<xsl:element name='Eligibility'>
 <xsl:variable name='toSend'>
  <xsl:value-of select="concat($idArray,',')"/>
    <xsl:variable name="text1" 
      select="substring-before(., ',')"/>
      <xsl:if test='not(contains($idArray, $text1))'>
      <xsl:value-of select="concat($text1,'')"/>
     </xsl:if>
   </xsl:variable>

 <xsl:call-template name="tokenize">
  <xsl:with-param name="businessID" select="$toSend" />
   <xsl:with-param name="separator" select="','" />
 </xsl:call-template>
 </xsl:element>


<xsl:template name="tokenize">

    <xsl:param name="businessID"/>
    <xsl:param name="separator" select="','"/>

    <xsl:variable name='toReceive'>
    <xsl:choose>
        <xsl:when test="not(contains($businessID, $separator))">
            <xsl:for-each select="//Package//Business_ID">
                <xsl:variable name='business' select='.'/>
                <xsl:if test="normalize-space($businessID)=$business">
                    <xsl:value-of select="concat(.././@ID,',')"/>

                </xsl:if>   
            </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
            <xsl:for-each select="//Package//Business_ID">
                <xsl:variable name='business' select='.'/>
                <xsl:if test="normalize-space(substring-before($businessID, 
 $separator))=$business">
                <xsl:value-of select="concat(.././@ID,',')"/>

                </xsl:if>   
            </xsl:for-each>
            <xsl:call-template name="tokenize">
                <xsl:with-param name="businessID" select="substring-
after($businessID, $separator)"/>
            </xsl:call-template>
        </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name='receive' select="$toReceive"/>

    <xsl:choose>
        <xsl:when test="not(contains($receive, ','))">
            <xsl:value-of select="$receive" />
        </xsl:when>
        <xsl:otherwise>

   <xsl:call-template name="distinctSubstrings">
     <xsl:with-param name="pText" select="$toReceive"/>
     <xsl:with-param name="poutDelim" select="','"/>
     <xsl:with-param name="pFoundDistinctSubs" select="','"/>
     <xsl:with-param name="pCountDistinct" select="0"/>
     <xsl:with-param name="count" select="0"/>
   </xsl:call-template>

 </xsl:otherwise>
 </xsl:choose>
 </xsl:template>

<xsl:template name="distinctSubstrings">
<xsl:param name="pText"/>
<xsl:param name="poutDelim"/>
<xsl:param name="pFoundDistinctSubs" select="','"/>
<xsl:param name="pCountDistinct" select="0"/>

 <xsl:if test="$pText">
  <xsl:variable name="vnextSub" select="substring-before(concat($pText, 
  ','), ',')"/>
  <xsl:variable name="vIsNewDistinct" 
 select="not(contains(concat($pFoundDistinctSubs, ','), concat(',', 
 $vnextSub, ',')))"/>
  <xsl:variable name="vnextDistinct" 
select="substring(concat($poutDelim,$vnextSub), 1 div $vIsNewDistinct)"/>

<xsl:choose>
    <xsl:when test="$pCountDistinct=0">
  <xsl:value-of select="substring($vnextDistinct, 2, string-
 length($vnextDistinct))"/>
  </xsl:when>
  <xsl:otherwise>
  <xsl:value-of select="$vnextDistinct"/>
  </xsl:otherwise>
</xsl:choose>
  <xsl:variable name="vNewFoundDistinctSubs" 
select="concat($pFoundDistinctSubs, $vnextDistinct)"/>
  <xsl:variable name="vnextOutDelim" select="substring(',', 2 - 
($pCountDistinct > 0))"/>

  <xsl:call-template name="distinctSubstrings">
    <xsl:with-param name="pText" select="substring-after($pText, ',')"/>
    <xsl:with-param name="pFoundDistinctSubs" 
select="$vNewFoundDistinctSubs"/>
    <xsl:with-param name="pCountDistinct" select="$pCountDistinct + 
$vIsNewDistinct"/>
    <xsl:with-param name="poutDelim" select="','"/>
  </xsl:call-template>
 </xsl:if>
</xsl:template>

XML Input: its quite a big file so can't put it here, what elitmately i am trying to acheive here is to get the Eligbility as an array of array.

Current Output:

"eligibility": [
      "3a8125fd-a5c6-427c-b165-bd03f71beda1,0ff7a8d9-91bd-4afa-b5cc-
       00d2e182dddf,357ab2c0-22db-4f47-9900-22905b08b019",
      "3a8125fd-a5c6-427c-b165-bd03f71beda1,0ff7a8d9-91bd-4afa-b5cc-
      00d2e182dddf,c12cb491-8408-490e-890b-f8886143f29e"
      ]

Desired Output:

"eligibility": [
      [3a8125fd-a5c6-427c-b165-bd03f71beda1,0ff7a8d9-91bd-4afa-b5cc-
      00d2e182dddf,357ab2c0-22db-4f47-9900-22905b08b019],
      [3a8125fd-a5c6-427c-b165-bd03f71beda1,0ff7a8d9-91bd-4afa-b5cc-
      00d2e182dddf,c12cb491-8408-490e-890b-f8886143f29e]
       ]